Worked Examples: Recurrences & Master Theorem

These examples are designed to step through the logical process of applying the algorithmic concepts.

Example 1: Master Case 1
❓ Problem: $T(n) = 9T(n/3) + n$.
💡 Solution: $a=9, b=3, \log_b a = 2$. $f(n)=n = O(n^{2-\epsilon})$. $T(n)=\Theta(n^2)$.
Example 2: Master Case 2
❓ Problem: $T(n) = T(2n/3) + 1$.
💡 Solution: $a=1, b=3/2, \log_b a = 0$. $f(n)=1 = \Theta(n^0)$. $T(n)=\Theta(\log n)$.
Example 3: Master Case 3
❓ Problem: $T(n) = 3T(n/4) + n \log n$.
💡 Solution: $\log_4 3 < 1$. $f(n)$ dominates. $T(n) = \Theta(n \log n)$.
Example 4: Substitution
❓ Problem: Guess $O(n)$ for $T(n)=2T(n/2)+n$.
💡 Solution: Fails. Attempt $cn \log n$. Succeeds.
Example 5: Uneven Split
❓ Problem: $T(n) = T(n/3) + T(2n/3) + n$.
💡 Solution: Recursion tree. Depth is $\log_{3/2} n$. Cost per level $n$. $O(n \log n)$.
Example 6: Non-Master
❓ Problem: $T(n) = 2^n T(n/2) + n^n$.
💡 Solution: Master Theorem doesn't apply (constant 'a' required).