This preview shows pages 1–8. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Analysis of Algorithms 1 Growth Rates Growth rates of functions: Linear n Quadratic n 2 Cubic n 3 In a loglog chart, the slope of the line corresponds to the growth rate of the function 1E+0 1E+2 1E+4 1E+6 1E+8 1E+10 1E+12 1E+14 1E+16 1E+18 1E+20 1E+22 1E+24 1E+26 1E+28 1E+30 1E+0 1E+2 1E+4 1E+6 1E+8 1E+10 n T ( n ) Cubic Quadratic Linear Analysis of Algorithms 2 Constant Factors The growth rate is not affected by constant factors or lowerorder terms Examples 10 2 n + 10 5 is a linear function 10 5 n 2 + 10 8 n is a quadratic function 1E+0 1E+2 1E+4 1E+6 1E+8 1E+10 1E+12 1E+14 1E+16 1E+18 1E+20 1E+22 1E+24 1E+26 1E+0 1E+2 1E+4 1E+6 1E+8 1E+10 n T ( n ) Quadratic Quadratic Linear Linear Analysis of Algorithms 3 BigOh Notation Given functions f ( n ) and g ( n ) , we say that f ( n ) is O ( g ( n )) if there are positive constants c and n such that f ( n ) cg ( n ) for n n Example: 2 n + 10 is O ( n ) 2 n + 10 cn ( c 2) n 10 n 10 / ( c 2) Pick c = 3 and n 0 = 10 1 10 100 1,000 10,000 1 10 100 1,000 n 3n 2n+10 n Analysis of Algorithms 4 BigOh Example Example: the function n 2 is not O ( n ) n 2 cn n c The above inequality cannot be satisfied since c must be a constant 1 10 100 1,000 10,000 100,000 1,000,000 1 10 100 1,000 n n^ 2 100n 10n n Analysis of Algorithms 5 More BigOh Examples 7n2 7n2 is O(n) need c > 0 and n 1 such that 7n2 cn for n n this is true for c = 7 and n = 1 3n 3 + 20n 2 + 5 3n 3 + 20n 2 + 5 is O(n 3 ) need c > 0 and n 1 such that 3n 3 + 20n 2 + 5 cn 3 for n n this is true for c = 4 and n = 21 3 log n + log log n 3 log n + log log n is O(log n) need c > 0 and n 1 such that 3 log n + log log n clog n for n n this is true for c = 4 and n = 2 Analysis of Algorithms 6 BigOh and Growth Rate The bigOh notation gives an upper bound on the growth rate of a function The statement f ( n ) is O ( g ( n )) means that the growth rate of f ( n ) is no more than the growth rate of g ( n ) We can use the bigOh notation to rank functions according to their growth rate f ( n ) is O ( g ( n )) g ( n ) is O ( f ( n )) g ( n ) grows more Yes No f ( n ) grows more No Yes Same growth Yes Yes Analysis of Algorithms 7 BigOh Rules If is f ( n ) a polynomial of degree d , then f ( n ) is O ( n d ) , i.e., 1. Drop lowerorder terms 2. Drop constant factors Use the smallest possible class of functions Say 2 n is O ( n ) instead of 2 n is O ( n 2 ) Use the simplest expression of the class Say 3 n + 5 is O ( n ) instead of 3 n + 5 is O (3 n ) Analysis of Algorithms...
View
Full
Document
This note was uploaded on 04/13/2010 for the course CS 560 taught by Professor Vd during the Spring '10 term at Wichita State.
 Spring '10
 VD

Click to edit the document details