1 Tirgul 2
Asymptotic Analysis
Asymptotic Analysis
- Motivation: Suppose you want to evaluate two
programs according to their run-time for inputs of size n. The first has run-time of: and the second has run-time of: For small inputs, it doesn’t matter, both programs will finish before you notice. What about (really) large inputs?
7 log
4
1 .
+ + ⋅
n
n
3859 2 ) 239 log 1000
( 200
+
+ + + ⋅
n
n n Big
- O
- Definition:
if there exist constants c>0 and n0 such that for all n>n0,
)) ( ( ) ( n g O n f =
) ( ) ( n g c n f ⋅ ≤
Big
- O
- In other words, g(n) bounds f(n) from above (for
large n’s) up to a constant.
- Examples:
why?) ( ) ( ) 5 ) ( ) 4 ) ( 10000 ) 3 ) ( 5 . ) 2 ) 1 ( 1000000 ) 1
2 2
n O n n O n n O n n O n O ≠ = = = =
Big
- Omega
- Definition:
if there exist constants c>0 and n0 such that for all n>n0,
)) ( ( ) ( n g n f Ω =
) ( ) ( n g c n f ⋅ ≥ Big
- Omega
- In other words, g(n) bounds f(n) from below (for large
n’s) up to a constant.
- Examples:
) ( ) 4 ) ( ) 3 ) ( 10000 ) 2 ) ( 5 . ) 1
2 2
n n n n n n n n Ω ≠ Ω = Ω = Ω =