Description:
- f(n) is O(g(n)) if there exist constants c>0 and n0≥0 such that 0≤f(n) ≤ c.g(n) for all n≥n0
- where f(n) denotes the worst-case running time
- ie. only 2n2→n2
Common mistake:
- g1(n)=10n3 and g2(n)=n3
- g1(n)=g2(n)=O(n3) but g1(n)=g2(n)
Properties:
- Reflexivity: f is O(f)
- Constants: if f is O(g) and c>0, then cf is O(g)
- Products: if f1 is O(g1) and f2 is O(g2) then f1+f2 is O(max{g1,g2})
- Transitivity: if f is O(g) and g is O(h) then f is O(h)
With multiple variables:
- f(m,n) is O(g(m,n)) if there exist constants c>0 and m0,n0≥0
- such that 0≤f(m,n)≤c.g(m,n) for all n≥n0,m≥m0
- ex: f(m,n)=32mn2+17n3 is both O(mn2+n3) and O(mn3)
- f(n) is O(n3) if there is condition that implies n>m
- f(m,n) is neither O(n3) nor O(mn2)