Jul 13, 2024
Big O Notation (Upper Bound)
F(n) = O(G(n))
means constants C
and N
exist such that for all n >= N
, |F(n)| <= C|G(n)|
2n^2 = O(n^3)
n^3
not O(n^2)
O(G(n)) = {F(n) : F(n) <= C|G(n)| for n >= N}
Big Omega Notation (Lower Bound)
F(n) = Ω(G(n))
means constants C
and N
exist such that for all n >= N
, |F(n)| >= C|G(n)|
√n = Ω(log n)
Theta Notation (Tight Bound)
F(n) = Θ(G(n))
means F(n)
is bounded both above and below by G(n)
up to constant factorsn^2 + O(n) = Θ(n^2)
Little o Notation (Strict Upper Bound)
F(n) = o(G(n))
means for every constant C > 0
, there exists an N
such that for all n > N
, |F(n)| < C|G(n)|
n^2 = o(n^3)
Little Omega Notation (Strict Lower Bound)
F(n) = ω(G(n))
means for every constant C > 0
, there exists an N
such that for all n > N
, |F(n)| > C|G(n)|
n^3 = ω(n^2)
Step 1: Guess the form of the solution
Step 2: Prove the guess by induction
Example Recurrence: T(n) = 4T(n/2) + n
T(n) = O(n^3)
T(1) ≤ C
T(n) ≤ Cn^3
T(n) = 2T(n/2) + n
T(n) = aT(n/b) + f(n)
Conditions: a >= 1
, b > 1
, f(n)
positive asymptotically
Compare f(n)
with n^log_b(a)
Three Cases:
f(n) = O(n^log_b(a) - ε)
for some ε > 0
→ T(n) = Θ(n^log_b(a))
f(n) = Θ(n^log_b(a) log^k(n))
for some k ≥ 0
→ T(n) = Θ(n^log_b(a) log^(k+1)(n))
f(n) = Ω(n^log_b(a) + ε)
for some ε > 0
af(n/b) ≤ cf(n)
for some c < 1
and sufficiently large n
T(n) = Θ(f(n))
Application Examples:
T(n) = 4T(n/2) + n
: Solution T(n) = Θ(n^2)
(Case 1)T(n) = 4T(n/2) + n^2
: Solution T(n) = Θ(n^2 log n)
(Case 2)T(n) = 4T(n/2) + n^3
: Solution T(n) = Θ(n^3)
(Case 3)Non-Master Theorem Example:
T(n) = 4T(n/2) + n^2/log n
: Does not fit cases; different approach needed.