Analysis of Algorithms (pt 2) (Chapter 4) COMP53 Oct 3, 2007.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

Estimating Running Time Algorithm arrayMax executes 3n  1 primitive operations in the worst case Define a Time taken by the fastest primitive operation.
CSC401 – Analysis of Algorithms Lecture Notes 1 Introduction
© 2004 Goodrich, Tamassia 1 Lecture 01 Algorithm Analysis Topics Basic concepts Theoretical Analysis Concept of big-oh Choose lower order algorithms Relatives.
Analysis of Algorithms Algorithm Input Output. Analysis of Algorithms2 Outline and Reading Running time (§1.1) Pseudo-code (§1.1) Counting primitive operations.
Analysis of Algorithms1 CS5302 Data Structures and Algorithms Lecturer: Lusheng Wang Office: Y6416 Phone:
Analysis of Algorithms (Chapter 4)
Analysis of Algorithms1 Estimate the running time Estimate the memory space required. Time and space depend on the input size.
Analysis of Algorithms
Fall 2006CSC311: Data Structures1 Chapter 4 Analysis Tools Objectives –Experiment analysis of algorithms and limitations –Theoretical Analysis of algorithms.
The Seven Functions. Analysis of Algorithms. Simple Justification Techniques. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer Goodrich,
Analysis of Algorithms1 CS5302 Data Structures and Algorithms Lecturer: Lusheng Wang Office: Y6416 Phone:
PSU CS 311 – Algorithm Design and Analysis Dr. Mohamed Tounsi 1 CS 311 Design and Algorithms Analysis Dr. Mohamed Tounsi
Analysis of Performance
CS2210 Data Structures and Algorithms Lecture 2:
Analysis of Algorithms Algorithm Input Output © 2014 Goodrich, Tamassia, Goldwasser1Analysis of Algorithms Presentation for use with the textbook Data.
Analysis of Algorithms Lecture 2
Analysis of Algorithms
Analysis Tools Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Algorithm Efficiency CS 110: Data Structures and Algorithms First Semester,
Analysis of Algorithms
Analysis of Algorithms1 The Goal of the Course Design “good” data structures and algorithms Data structure is a systematic way of organizing and accessing.
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)
Asymptotic Analysis of Algorithms
Data Structures Lecture 8 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
Computer Science 212 Title: Data Structures and Algorithms
Analysis of Algorithms1 Running Time Pseudo-Code Analysis of Algorithms Asymptotic Notation Asymptotic Analysis Mathematical facts.
Analysis of Algorithms Algorithm Input Output Last Update: Aug 21, 2014 EECS2011: Analysis of Algorithms1.
1 Analysis of Algorithms CS 105 Introduction to Data Structures and Algorithms.
1 Dr. J. Michael Moore Data Structures and Algorithms CSCE 221 Adapted from slides provided with the textbook, Nancy Amato, and Scott Schaefer.
Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =
Dr. Alagoz CHAPTER 2 Analysis of Algorithms Algorithm Input Output An algorithm is a step-by-step procedure for solving a problem in a finite amount of.
CSC401 – Analysis of Algorithms Chapter 1 Algorithm Analysis Objectives: Introduce algorithm and algorithm analysis Discuss algorithm analysis methodologies.
Zeinab EidAlgorithm Analysis1 Chapter 4 Analysis Tools.
CSC401 – Analysis of Algorithms Lecture Notes 2 Asymptotic Analysis Objectives: Mathematics foundation for algorithm analysis Amortization analysis techniques.
Analysis of Algorithms Algorithm Input Output An algorithm is a step-by-step procedure for solving a problem in a finite amount of time.
Analysis of Algorithms Algorithm Input Output © 2010 Goodrich, Tamassia1Analysis of Algorithms.
Analysis of algorithms. What are we going to learn? Need to say that some algorithms are “better” than others Criteria for evaluation Structure of programs.
CSC Devon M. Simmonds University of North Carolina, Wilmington CSC231 Data Structures.
1 Dr. Scott Schaefer Data Structures and Algorithms CSCE 221H.
Lecture aid 1 Devon M. Simmonds University of North Carolina, Wilmington CSC231 Data Structures.
Announcement We will have a 10 minutes Quiz on Feb. 4 at the end of the lecture. The quiz is about Big O notation. The weight of this quiz is 3% (please.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
1 COMP9024: Data Structures and Algorithms Week Two: Analysis of Algorithms Hui Wu Session 2, 2014
Analysis of Algorithms Algorithm Input Output © 2014 Goodrich, Tamassia, Goldwasser1Analysis of Algorithms Presentation for use with the textbook Data.
(Complexity) Analysis of Algorithms Algorithm Input Output 1Analysis of Algorithms.
Analysis of Algorithms
Analysis of Algorithms
COMP9024: Data Structures and Algorithms
COMP9024: Data Structures and Algorithms
GC 211:Data Structures Week 2: Algorithm Analysis Tools
GC 211:Data Structures Algorithm Analysis Tools
03 Algorithm Analysis Hongfei Yan Mar. 9, 2016.
Analysis of Algorithms
COMP9024: Data Structures and Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
GC 211:Data Structures Algorithm Analysis Tools
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Presentation transcript:

Analysis of Algorithms (pt 2) (Chapter 4) COMP53 Oct 3, 2007

Best, Worst and Average Case For a particular problem size n, we can find: Best case: the input that can be solved the fastest Worst case: the input that will take the longest Average case: average time for all inputs of the same size.

Methods of Analysis Experimental Studies: Run experiments on implementations of algorithms and record actual time or operation counts. Theoretical Analysis: Determine time or operation counts from mathematical analysis of the algorithm – doesn’t require an implementation (or even a computer)

Theoretical Analysis Uses a high-level description of the algorithm instead of an implementation Characterizes running time as a function of the input size, n. Takes into account all possible inputs Allows us to evaluate the speed of an algorithm independent of the hardware/software environment

Seven Important Functions Seven functions that often appear in algorithm analysis: – Constant  1 – Logarithmic  log n – Linear  n – N-Log-N  n log n – Quadratic  n 2 – Cubic  n 3 – Exponential  2 n In a log-log chart, the slope of the line corresponds to the growth rate of the function

Growth Functions

Reasonable Time Assume GHz machine: 10 6 operations/second Clearly, any algorithm requiring more than operations is impractical MinuteHourDayMonthYear 10 8 ops10 9 ops10 11 ops10 12 ops10 13 ops

Growth Functions < day< month> year

Big-Oh Notation f(n) is O(g(n)) if there are positive constants c and n 0 such that f(n)  cg(n) for n  n 0 Example: 2n  10 є O(n) 2n  10  cn for c  3 and n >= n 0  10

Big-Oh Example Example: n 2 is not O(n) There is no value of c such that n 2  cn, as n  ∞

Comparing Growth Rates f(n) є O(g(n)) means that the growth rate of f(n) is no more than the growth rate of g(n) g(n) is an upper bound on the value of f(n)

Asymptotic Algorithm Analysis The asymptotic analysis of an algorithm determines the running time in big-Oh notation To perform the asymptotic analysis – We find the worst-case number of basic operations as a function of the input size – We express this function with big-Oh notation Example: – We determine that algorithm arrayMax executes at most 8n  2 primitive operations – We say that algorithm arrayMax “runs in O(n) time”

Example: Prefix Averages The i -th prefix average of an array X is average of the first (i  1) elements of X: A[i]  X[0]  X[1]  …  X[i])/(i+1) This has applications to financial analysis

Prefix Averages: Algorithm 1 Algorithm prefixAverages1(X, n) Input array X of n integers Output array A of prefix averages of X A  new array of n integers for i  0 to n  1 do s  X[0] for j  1 to i do s  s  X[j] A[i]  s  (i  1) return A basic operation: addition

Algorithm 1 Analysis Number of additions is 1  2  …  n-1 The sum of the first n-1 integers is (n-1)n  2 Algorithm prefixAverages1 є O(n 2 ) for i  0 to n  1 do for j  1 to i do s  s  X[j]

Prefix Averages (Algorithm 2) Algorithm prefixAverages2(X, n) Input array X of n integers Output array A of prefix averages of X A  new array of n integers s  0 for i  0 to n  1 do s  s  X[i] A[i]  s  (i  1) return A basic operation: addition

Algorithm 2 Analysis Number of additions is 1  1  …  1 = n Algorithm prefixAverages2 є O(n) for i  0 to n  1 do s  s + X[i]

Relatives of Big-Oh big-Omega f(n) є  (g(n)) if f(n)  cg(n) for n  n 0 big-Theta f(n) є  (g(n)) if c’g(n)  f(n)  c’’g(n) for n  n 0

Intuition for Asymptotic Notation f(n) є O(g(n)) f(n) is asymptotically smaller or equal to g(n) f(n) є  (g(n)) f(n) is asymptotically bigger or equal to g(n) f(n) є  (g(n)) f(n) is asymptotically the same to g(n)

Big-Oh

Big-Omega

Big-Theta

Example Uses  and  5n 2 is  (n 2 ) 5n 2 is  (n) 5n 2 is  (n 2 )