220handout Lecture04
220handout Lecture04
COMPSCI 220
Number of data items processed per: 1 minute 1 day 1 year 1 century 10 14,400 5.26106 5.26108 10 3,997 883,895 6.72107 10 1,275 65,128 1.40106 10 10 10 379 112 20
COMPSCI 220 - AP G Gimel'farb
7,252 807 29
72,522 3,746 35
2
Lecture 4
Big-Oh: Scaling
For all c > 0 cf is O(f ) where f f(n) Proof: cf(n) < (c+)f(n) holds for all n > 0 and > 0
Constant factors are ignored. Only the powers and functions of n should be exploited It is this ignoring of constant factors that motivates for such a notation! In particular, f is O(f ) Examples: 50n O(n) 0.05n O(n) 50000000n O(n) 0.0000005n O(n)
Lecture 4 COMPSCI 220 - AP G Gimel'farb 6
COMPSCI 220
Big-Oh: Transitivity
If h is O(g) and g is O(f ), then h is O(f ) Informally: if h grows at most as fast as g, which grows at most as fast as f, then h grows at most as fast as f
Examples: h O(g); g O(n2) h O(n2) log10n O(n0.01); n0.01 O(n) log10n O(n) 2n O(3n); n50 O(2n) n50 O(3n)
Lecture 4 COMPSCI 220 - AP G Gimel'farb 7
Rule of Sums
Examples: if hO(n) and gO(n2), then ghO(n3) if hO(log n) and gO(n), then ghO(n log n)
Lecture 4 COMPSCI 220 - AP G Gimel'farb 9 Lecture 4 COMPSCI 220 - AP G Gimel'farb 10
Ex. 1.24: Logarithmic functions grow slower than powers: logbn is O(nk) for all b>1, k>0
logbn is O(log n) for all b>1: logbn = logba logan log n is O(n) n log n is O(n2)
COMPSCI 220 - AP G Gimel'farb 12
Lecture 4