Algorithm Analysis Lakshmish Ramaswamy. What Constitutes Good Software? Code correctness Good design Code reusability OO design can help us in achieving.

Slides:



Advertisements
Similar presentations
Algorithm Analysis Input size Time I1 T1 I2 T2 …
Advertisements

Md. Ahsan Arif, Assistant Professor, Dept. of CSE, AUB
Growth-rate Functions
CSE Lecture 3 – Algorithms I
Fundamentals of Python: From First Programs Through Data Structures
ALG0183 Algorithms & Data Structures Lecture 3 Algorithm Analysis 8/25/20091 ALG0183 Algorithms & Data Structures by Dr Andy Brooks Weiss Chapter 5 Sahni.
Computer science is a field of study that deals with solving a variety of problems by using computers. To solve a given problem by using computers, you.
Analysys & Complexity of Algorithms Big Oh Notation.
What is an Algorithm? (And how do we analyze one?)
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
Introduction to Analysis of Algorithms
Complexity Analysis (Part I)
CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Algorithmic Complexity Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Cmpt-225 Simulation. Application: Simulation Simulation  A technique for modeling the behavior of both natural and human-made systems  Goal Generate.
Design and Analysis of Algorithms Chapter Analysis of Algorithms Dr. Ying Lu August 28, 2012
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Algorithm Analysis (Big O)
Algorithm Analysis Dr. Bernard Chen Ph.D. University of Central Arkansas.
Chapter 6 Algorithm Analysis Bernard Chen Spring 2006.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Program Performance & Asymptotic Notations CSE, POSTECH.
CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a lgorithms.
Week 2 CS 361: Advanced Data Structures and Algorithms
Data Structures & AlgorithmsIT 0501 Algorithm Analysis I.
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
{ CS203 Lecture 7 John Hurley Cal State LA. 2 Execution Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
Algorithm Analysis. Algorithm An algorithm is a clearly specified set of instructions which, when followed, solves a problem. recipes directions for putting.
Algorithm Input Output An algorithm is a step-by-step procedure for solving a problem in a finite amount of time. Chapter 4. Algorithm Analysis (complexity)
DISCRETE MATHEMATICS I CHAPTER 11 Dr. Adam Anthony Spring 2011 Some material adapted from lecture notes provided by Dr. Chungsim Han and Dr. Sam Lomonaco.
Unit III : Introduction To Data Structures and Analysis Of Algorithm 10/8/ Objective : 1.To understand primitive storage structures and types 2.To.
Chapter 12 Recursion, Complexity, and Searching and Sorting
Chapter 3 Sec 3.3 With Question/Answer Animations 1.
Algorithm Evaluation. What’s an algorithm? a clearly specified set of simple instructions to be followed to solve a problem a way of doing something What.
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Algorithms and Algorithm Analysis The “fun” stuff.
Complexity of Algorithms
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Chapter 10 Algorithm Analysis.  Introduction  Generalizing Running Time  Doing a Timing Analysis  Big-Oh Notation  Analyzing Some Simple Programs.
Algorithm Analysis Data Structures and Algorithms (60-254)
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Algorithms and data structures: basic definitions An algorithm is a precise set of instructions for solving a particular task. A data structure is any.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
CSC310 © Tom Briggs Shippensburg University Fundamentals of the Analysis of Algorithm Efficiency Chapter 2.
Algorithm Analysis Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Lecture 10 – Algorithm Analysis.  Next number is sum of previous two numbers  1, 1, 2, 3, 5, 8, 13, 21 …  Mathematical definition 2COMPSCI Computer.
Algorithm Analysis Chapter 5. Algorithm An algorithm is a clearly specified set of instructions which, when followed, solves a problem. –recipes –directions.
Efficiency of Algorithms. Node - data : Object - link : Node + createNode() + getData() + setData() + getLink() + setLink() + addNodeAfter() + removeNodeAfter()
Algorithm Analysis (Big O)
Computer science is a field of study that deals with solving a variety of problems by using computers. To solve a given problem by using computers, you.
Searching Topics Sequential Search Binary Search.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
Algorithm Analysis 1.
Lecture 15.
Analysis of Algorithms
GC 211:Data Structures Week 2: Algorithm Analysis Tools
Analysis of Algorithms
GC 211:Data Structures Algorithm Analysis Tools
Algorithm An algorithm is a finite set of steps required to solve a problem. An algorithm must have following properties: Input: An algorithm must have.
Objective of This Course
GC 211:Data Structures Algorithm Analysis Tools
Programming and Data Structure
Analysis of Algorithms
Analysis of Algorithms
Presentation transcript:

Algorithm Analysis Lakshmish Ramaswamy

What Constitutes Good Software? Code correctness Good design Code reusability OO design can help us in achieving both But what about performance? –Software can become useless if performance is poor

Factors Affecting Performance Platform where software runs –Resources –Operating system –Load on the platform Programming language Compiler Algorithms used

Algorithm A clearly specified set of instructions for solving a particular problem Independent of programming language Software can be comprised of several algorithms –Course maintenance software Algorithms vary in terms of time and memory requirements Algorithm analysis - science of determining time and space requirement

Chapter Overview Estimation of running time of algorithm Mathematical technique to describe/reason about running time –Comparing algorithms without implementing Techniques for reducing time Example – Searching (Binary search)

Algorithm Analysis Reasoning about algorithms can be complex –Performance of different algorithms may vary with input Time requirement generally depends upon amount of input data –Searching in 1 million word file takes much longer than searching 10 word file Running time is a function of input size –Exact value may depend upon many factors

An Example

How to Compare Algorithms? In general, look for trends –Not individual points on the curve An algorithm is better if its running time increases slowly with increasing input size –Linear is better than O(N long N), which is better than quadratic Do you need to choose the best algorithm always? –Not if you know the range of input values

More on Functions Usually expressed as sum of components (terms) Dominant term – Component that has the maximum impact on the growth rate 10N 3 + N N + 80 Functions compared in terms of dominant terms Cubic function – Dominant term is 3 rd power Quadratic function – Dominant term is 2 nd power

Why Analyze Growth Rates? Dominant term contributes maximum to the value of function for large input sizes –For N = 1000, 99.99% of value contributed by N 3 term Constants are not meaningful across platforms –Compiler, architecture and OS have significant impact on the constants We are mostly concerned with large inputs –Algorithms have comparable performances on small inputs

Example (Contd.)

Growth Rates of Functions

The Big-Oh Notation Captures the dominant term of the function The constants associated with the dominant term are not included If dominant term is 10N 2, function is O(N 2 ) If dominant term is 0.5N 3 function is O(N 3 ) If dominant term is 2N log(N) function is O(N logN)

Example Algorithms Finding minimum (maximum) element in an array Finding average (mean) of an array Calculating variance of a population Calculating closest points in a plane Calculating co-linear points in plane

Minimum Element ALGORITHM: min <- array[0] i <- 1 while (i < numElements) if (array[i] < min) min <- array[i] endif endwhile Fixed amount of work (constant) for each element Linear or O(N) running time

Average of Array Elements ALGORITHM: sum <- 0.0 i <- 0 while (i < numElements) sum <- sum + array[i] endwhile average <- sum/numElements Again O(N) algorithm

Variance of Population in Array ALGORITHM: FIRST CALCULATE AVERAGE (Use previous alg.) varSum <- 0 i <- 0 while (i < numElements) varSum <- varSum + (array[i]-average)^2 endwhile variance <- varSum/numElements Two phases –Constant amount of work per element in each phase O(N) algorithm

Calculating Closest Points in Plane ALGORITHM: Select any two points in the set Mindist <- Euclidean distance between the selected point For every pair of points if Mindist > distance between pair Mindist <- distance between pair endif Endfor N (N-1)/2 comparisons O(N 2 ) algorithm

Colinear Points in Plane Problem: Given set of points in plane determine if any three form a straight line ALGORITHM: For every triplets of points Check if they form a straight line \\ How do you do this? If yes output and break Number of triplets = N (N-1) (N-2)/6 O(N 3 ) algorithm