Chapter 2 introduction to The Design & Fundamentals of the Analysis Analysis of Algorithms of Algorithm Efficiency 2ND EDITION Anany Levitin PEARSON Addison Wesley Copyright 2007 Pearson Addison-Wesley. All rights reserved
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency Copyright © 2007 Pearson Addison-Wesley. All rights reserved
Analysis of algorithms 口 Issues correctness time efficiency space efficiency optimality 口 Approaches theoretical analysis ° empirical analysIs Copyright 2007 Pearson Addison-Wesley. All rights reserved A Levitin "Intoducion to the Design Analysis of Algorithms, 2nd ed, Ch 2
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2 nd ed., Ch. 2 2-1 Analysis of algorithms Issues: • correctness • time efficiency • space efficiency • optimality Approaches: • theoretical analysis • empirical analysis
Theoretical analysis of time efficiency Time efficiency is analyzed by determining the number of repetitions of the basic operation as a function of input size o Basic operation: the operation that contributes the most towards the running time of the algorithm Input size ()c2C() running time execution time Number of times for basic operation basic operation is or cost executed Note: Different basic operations may cost differently Copyright 2007 Pearson Addison-Wesley. All rights reserved A Levitin "Intoducion to the Design Analysis of Algorithms, 2nd ed, Ch 2
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2 nd ed., Ch. 2 2-2 Theoretical analysis of time efficiency Time efficiency is analyzed by determining the number of repetitions of the basic operation as a function of input size Basic operation: the operation that contributes the most towards the running time of the algorithm T(n) ≈ copC(n) running time execution time for basic operation or cost Number of times basic operation is executed input size Note: Different basic operations may cost differently!
Input size and basic operation examples Problem Input size measure Basic operation Searching for key in a Number of list's items, Kev comparison list of n items l.e. n Multiplication of two Matrix dimensions or Multiplication of two matrices total number of elements numbers Checking primality of n'size= number of digits Di vIsIon a given integer n (in binary representation) Visiting a vertex or ypical graph problem #vertices and/oredges traversing an edge Copyright 2007 Pearson Addison-Wesley. All rights reserved A Levitin "Intoducion to the Design Analysis of Algorithms, 2nd ed, Ch 2
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2 nd ed., Ch. 2 2-3 Input size and basic operation examples Problem Input size measure Basic operation Searching for key in a list of n items Number of list’s items, i.e. n Key comparison Multiplication of two matrices Matrix dimensions or total number of elements Multiplication of two numbers Checking primality of a given integer n n’size = number of digits (in binary representation) Division Typical graph problem #vertices and/or edges Visiting a vertex or traversing an edge
Empirical analysis of time efficiency o Select a specific(typical) sample of inputs o Use physical unit of time(e.g, milliseconds) or Count actual number of basic operation's executions D Analyze the empirical data Copyright 2007 Pearson Addison-Wesley. All rights reserved A Levitin "Intoducion to the Design Analysis of Algorithms, 2nd ed, Ch 2
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2 nd ed., Ch. 2 2-4 Empirical analysis of time efficiency Select a specific (typical) sample of inputs Use physical unit of time (e.g., milliseconds) or Count actual number of basic operation’s executions Analyze the empirical data