COT5407-Class03

COT5407-Class03 - Analysis of Algorithms 1 Growth Rates...

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 Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Analysis of Algorithms 1 Growth Rates Growth rates of functions: Linear ≈ n Quadratic ≈ n 2 Cubic ≈ n 3 In a log-log 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 lower-order 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 Big-Oh 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 Big-Oh 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 Big-Oh Examples 7n-2 7n-2 is O(n) need c > 0 and n ≥ 1 such that 7n-2 ≤ c•n 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 ≤ c•n 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 ≤ c•log n for n ≥ n this is true for c = 4 and n = 2 Analysis of Algorithms 6 Big-Oh and Growth Rate The big-Oh 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 big-Oh 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 Big-Oh Rules If is f ( n ) a polynomial of degree d , then f ( n ) is O ( n d ) , i.e., 1. Drop lower-order 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 ) ”...
View Full Document

This note was uploaded on 09/13/2011 for the course COT 5407 taught by Professor Staff during the Spring '08 term at FIU.

Page1 / 28

COT5407-Class03 - Analysis of Algorithms 1 Growth Rates...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online