The Master Theorem & Akra–Bazzi
Solving divide-and-conquer recurrences, with proofs.
In 1980 Bentley, Haken and Saxe gave one recipe for the recurrences of divide-and-conquer algorithms, and textbooks turned it into the master theorem. Underneath, it is a statement about a geometric series. Once you see the series, you can prove the theorem, extend it to , and go beyond it to the unequal splits of median of medians.
What you’ll learn
- State the master theorem exactly, with its , its factor and the regularity condition, and apply it to recurrences from real algorithms.
- Prove the theorem for exact powers of from the recursion tree, and derive the extended case 2 for every real .
- Explain how floors and ceilings are handled, and why the regularity condition is sufficient but not necessary.
- Solve recurrences with unequal splits by the Akra–Bazzi theorem, and sketch its proof.
The theorem, exactly
The master theorem asks how compares with polynomially: in cases 1 and 3 one must beat the other by a factor . Case 2 allows extra log factors. Older editions stated it only for , which left unsolved; with it is .
The regularity condition is rarely a burden: for with , and . It exists to exclude driving functions that wobble, as you will see.
| Recurrence | Comparison | Solution | |
|---|---|---|---|
| : case 1 | |||
| : case 2, | |||
| case 2, | |||
| case 3; | |||
| no case: is not allowed | , see the proof |
Which case of the master theorem solves , and what is the answer?
- Case 1:
- Case 3:
- Case 2:
- No case applies
Show the answer
C. Case 2:
, so the watershed function is , exactly : case 2 with gives . Every level of the tree costs .
The proof, from the recursion tree
Take so that every division is exact, and let . Level of the recursion tree has nodes of size , and the bottom level has leaves. Summing level by level gives the lemma everything rests on:
Case 1. With , and , each term is a geometric term with ratio :
So the leaves dominate: . Case 2. Now , and . Substitute :
Case 3. Regularity applied times gives , a decreasing geometric series. The root alone already contributes , and outweighs the leaves:
Every real . Case 2's proof never used except in summing , which is for , the harmonic number for , and a convergent series for . That is the extended case 2:
Think first Use the extended case 2 to solve . Which levels of the recursion tree carry most of the work?
Here , so : the log factor disappears. Level costs , so the levels near the leaves, where is small, carry most of the weight, and all internal levels together add at most . As in case 1 the leaves set the order of growth, but the level costs now shrink only polynomially toward the root instead of geometrically.
Floors, ceilings and wobbly driving functions
Real code splits into and , so is rarely a power of . The fix is to bound the sizes. With ceilings, the size at depth satisfies , so
and with floors . Down to depth every size is within an additive constant of , a constant number of extra levels reaches the base cases, and for polynomially bounded such as one has . The three sums of the proof reappear with different constants, and the theorem holds for every .
The same comparison principle rescues many near misses: if and the recurrences driven by and have the same order of growth, so does yours. When the gap is real, as between and , go back to the level sums.
Akra–Bazzi: unequal splits
Median of medians splits elements into recursive calls on about and elements; an unbalanced partition splits into and . No single describes these, and the master theorem is silent. Akra and Bazzi found the general rule, and Leighton gave a cleaner statement with a short inductive proof.
The exponent exists and is unique because falls continuously and strictly from to as grows. With one term, gives , and makes the integral , or as is below, equal to or above : the three cases of the master theorem, with floors, ceilings and small shifts included, and no regularity condition. The Akra–Bazzi theorem needs only polynomial growth of .
| Recurrence | Source | Solution | |
|---|---|---|---|
| median of medians | |||
| an uneven partition | |||
| two kinds of subproblems | |||
| , base cases up to 34 | merge sort with padding |
For , find the Akra–Bazzi exponent , the solution of .
Show the answer
2
Put : then , so and . The integral is , so : the driving function matches the watershed , the analogue of case 2.
Let , and ignore the for now. Split each integral at and use :
On , polynomial growth gives , also , and the interval has length . So the subtracted term is , and satisfies the recurrence up to an error of the same order as :
Induction. If for smaller , then once is large enough for to absorb . The lower bound is symmetric with small. The perturbations are absorbed by strengthening the hypothesis with a factor such as , which is where is used.
Exact solutions, random splits, and history
hides structure. Merge sort's worst-case number of comparisons satisfies with , and its exact solution is
Writing gives : the coefficient of is not a constant but a periodic function of , oscillating between and about . For , . Precise analyses of divide-and-conquer recurrences, by Mellin transforms (Flajolet and Golin, 1994) and by the discrete master theorem of Drmota and Szpankowski (2013), explain when such periodic terms appear.
Randomized divide and conquer brings recurrences with random subproblem sizes, as in quickselect, where a random pivot leaves a random fraction of the array. Karp (1994) gave a cookbook for recurrences of the form with a random size : under mild monotonicity conditions, if , let solve the deterministic recurrence ; then the random cost exceeds only with a probability that decays exponentially in . Replacing the random size by its expectation is safe, with high probability.
Key takeaways
- The master theorem compares with the watershed : polynomially smaller gives , equal up to gives , polynomially larger and regular gives .
- The proof is the recursion-tree identity : an increasing geometric series, a flat one, or a decreasing one.
- The same sum yields the extended case 2 for every real : appears at , and for the log factor disappears.
- Akra–Bazzi handles unequal splits and small shifts: pick with , then , with no regularity condition.
- hides periodic lower-order terms, such as the oscillating linear term of merge sort's exact cost, and random splits need probabilistic recurrences such as Karp's.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Why does case 3 of the master theorem need the regularity condition with ?
- To make the level costs a decreasing geometric series, so that the root's cost dominates
- To guarantee that is polynomially larger than
- To handle floors and ceilings
- Because without it may not be defined
Show the answer
A. To make the level costs a decreasing geometric series, so that the root's cost dominates
Iterating it gives , so the internal levels sum to at most . It is sufficient, not necessary: violates it, yet shows by comparison.
What is the solution of ?
Show the answer
C.
The watershed function is and : the extended case 2 with . The levels cost in turn, which sum to , so .
For , the Akra–Bazzi exponent solves . Why is ?
- Because , so the answer is divided by
- Because , so , and then the driving function dominates
- Because the master theorem applies with ,
- Because both subproblems are smaller than
Show the answer
B. Because , so , and then the driving function dominates
At the sum is , and the sum decreases in , so . Then , and . In the recursion tree, the level costs shrink by the factor : a decreasing geometric series dominated by the root.
Merge sort's worst-case comparison count is exactly . Which statement is true?
- is , with a coefficient of that oscillates periodically in instead of converging
- oscillates forever without a limit
- The formula contradicts the master theorem, which predicts
Show the answer
B. is , with a coefficient of that oscillates periodically in instead of converging
With , , and wanders between and about as grows. The master theorem's is correct; it just hides this periodic second-order term.
Further reading
- T. H. Cormen, C. E. Leiserson, R. L. Rivest & C. Stein, Introduction to Algorithms, 4th ed. (MIT Press, 2022), chapter 4.
- J. L. Bentley, D. Haken & J. B. Saxe, "A general method for solving divide-and-conquer recurrences," SIGACT News 12(3) (1980), 36–44.
- M. Akra & L. Bazzi, "On the solution of linear recurrence equations," Computational Optimization and Applications 10(2) (1998), 195–210.
- T. Leighton, "Notes on better master theorems for divide-and-conquer recurrences," MIT lecture notes (1996).