Standard methods for simplifying the asymptotic analysis of algorithms
Algorithm Analysis
- The running time T is a function of the amount of input n, T(n)=f(n)
Θ-notation
- Θ(g(n))={f(n):0≤c1g(n)≤f(n)≤c2g(n) for all n≥n0}
- f(n)=Θ(g(n)) if there is positive constants c1,c2
- g(n) is an asymptotically tight bound for f(n)
- f(n) is nonnegative whenever n is sufficiently large
- g(n) must be asymptotically nonnegative
Example : f(n)=21n2−3n=Θ(n2)=g(n)
- c1n2≤21n2−3n≤c2n2 for all n≥n0
- Dividing by n2
- c1≤21−n3≤c2
- Right hand inequality
- Hold for any value of n≥1 by choosing any constant c2≥21
- Left hand inequality
- Hold for any value of n≥7 by choosing any constant c1≤141
- Thus, by choosing c1=141,c2≥21,n0≥7,
we can verify that 21n2−3n=Θ(n2)
O-notation
- Given an upper bound on a function
- O(g(n))={f(n):0≤f(n)≤cg(n) for all n≥n0}
- There exist positive constants c and n0
Ω-notation
- Lower bound on a function
- Ω(g(n))={f(n):0≤cg(n)≤f(n) for all n≥n0}
- Positive constants c and n0
Asymptotic Notation
- We have f(n)=Θ(g(n))
if and only if f(n)=O(g(n)) and f(n)=Ω(g(n))
Properties of Big-O
- If T1(n)=O(f(n)) and T2(n)=O(g(n)),
- T1(n)+T2(n)=max(O(f(n)),O(g(n)))
- Lower order terms are ignored
- O(c∗f(n))=O(f(n))
- Constants and lower order terms may matter especially when the input size is small
- For large n, dominant term is usually indicative of algorithm's behavior
- For small n, typically programs on small inputs run so fast we don't care anyway