Master the analysis of divide-and-conquer algorithms through recursion trees, the Master Theorem, and geometric series
Divide-and-conquer algorithms break problems into subproblems, solve them recursively, then combine results. But how do we determine their complexity? The answer lies in understanding recurrence relations.
The Master Theorem provides a powerful shortcut for recurrences of the form T(n) = aT(n/b) + f(n). By comparing the work at different levels of the recursion tree, we can immediately determine if the algorithm is O(n), O(n log n), O(n²), or something else entirely.
In this section, you'll visualize recursion trees, discover why the Master Theorem works through geometric series, and extend to more complex recurrences with the Akra-Bazzi method and characteristic equations.
Every divide-and-conquer recurrence T(n) = aT(n/b) + f(n) corresponds to a recursion tree. At each level, the problem splits into a subproblems of size n/b. Watch how work distributes across levels!
| Level | # Problems | Size | Work/Problem | Total Work | Visual |
|---|---|---|---|---|---|
| 0 | 2^0 = 1 | 16 | 16.0 | 16.0 | |
| 1 | 2^1 = 2 | 8 | 8.0 | 16.0 | |
| 2 | 2^2 = 4 | 4 | 4.0 | 16.0 | |
| 3 | 2^3 = 8 | 2 | 2.0 | 16.0 | |
| 4 | 2^4 = 16 | 1 | 1.0 | 16.0 |
The Master Theorem has three cases based on comparing f(n) to nlogb(a). This determines whether work is dominated by leaves (Case 1), balanced across levels (Case 2), or dominated by the root (Case 3).
The total work is a geometric series with ratio r = a/bd. When r < 1, the series converges (root dominates). When r > 1, it diverges (leaves dominate). When r = 1, all terms are equal (balanced).
Total work T(n) is a geometric series:
where r = a/bd is the ratio between consecutive levels, and L = logb(n) is the tree depth.
At level k, there are ak subproblems, each of size n/bk.
Work at level k = ak × (n/bk)d = nd × (a/bd)k = nd × rk
Total work = nd × Σk=0..L rk
This is a geometric series! Its sum depends on whether r < 1, r = 1, or r > 1.
What if subproblems have different sizes? The Akra-Bazzi method handles T(n) = T(n/2) + T(n/3) + f(n) by finding p where the sum of ai/bip equals 1.
The Akra-Bazzi method solves recurrences with multiple, differently-sized subproblems:
Find p where Σ ai/bip = 1, then compare f(n) to np.
The Master Theorem is a special case of Akra-Bazzi where all subproblems have the same size: T(n) = aT(n/b) + f(n).
In this case, finding p is simple: a/bp = 1 → p = logb(a).
Akra-Bazzi handles more general recurrences where subproblems may have different sizes, like T(n) = T(n/2) + T(n/3) + n.
For recurrences like Fibonacci (T(n) = T(n-1) + T(n-2)), the characteristic equation method finds closed-form solutions. The roots determine exponential growth rates like the golden ratio.
For linear homogeneous recurrences, the closed-form solution comes from solving a polynomial equation. The roots determine the growth rate.
You now have a complete toolkit for analyzing recursive algorithms:
Next: We'll explore information-theoretic lower bounds, proving that comparison-based sorting must be Ω(n log n) using decision trees and entropy.