Sub topic 13
Why the Three Cases Arise: A Proof Sketch
The master theorem can look like three unrelated rules. This chapter shows that they come from one calculation. You draw the recursion tree for T(n) = aT(n/b) + f(n), add up the work on each level, and check whether those level sums grow, stay flat, or shrink as you go down the tree. Each master theorem case matches one of those three patterns of a geometric series.
This chapter assumes you have read the earlier chapters on recursion trees and on the three cases. It also assumes you can sum a geometric series and use the identity a^(logb n) = n^(logb a). To keep the algebra clean, take n to be an exact power of b and T(1) = Θ(1). The later chapter on floors, ceilings, and base cases explains why dropping those assumptions does not change the asymptotic answer.
Throughout, write c = log_b a for the critical exponent, so that a = b^c.
Step 1: The Exact Sum from the Recursion Tree
Expand the recurrence into a tree:
- Level 0 (the root) has 1 node with a problem of size n, costing f(n).
- Level 1 has a nodes, each of size n/b, costing a·f(n/b) in total.
- Level j has a^j nodes, each of size n/b^j, costing a^j·f(n/b^j) in total.
- The sizes reach 1 at depth log_b n, which is where the leaves are.
The number of leaves is a^(logb n) = n^(logb a) = n^c. Each leaf costs Θ(1), so the leaves together cost Θ(n^c). Adding the internal levels gives an exact decomposition:
T(n) = Θ(n^c) + g(n), where g(n) = sum over j = 0 to (log_b n) − 1 of a^j·f(n/b^j).
The whole proof is about comparing g(n) with the leaf term Θ(n^c). Whichever is larger, or both if they match, sets the answer.
Step 2: Level Sums Form a Geometric Series
Take f(n) = n^d first. The cost of level j is
a^j·(n/b^j)^d = n^d·(a/b^d)^j.
So the level costs form a geometric series with first term n^d and ratio r = a/b^d. Because a = b^c, the ratio is r = b^(c−d), and the comparison between d and c turns into a comparison between r and 1:
| Comparison | Ratio r = a/b^d | Level costs going down | Dominant part | Result |
|---|---|---|---|---|
| d < c | r > 1 | grow geometrically | leaves | Θ(n^c) |
| d = c | r = 1 | all equal to n^c | every level | Θ(n^c log n) |
| d > c | r < 1 | shrink geometrically | root | Θ(n^d) |
The following script prints the level costs of three recurrences that share f(n) = n^2 and b = 2 but use a = 8, 4, and 2. Their critical exponents are 3, 2, and 1, so the three examples land in case 1, case 2, and case 3.
def level_costs(a, b, f, n):
"""Return the internal level costs and the leaf count for T(n) = aT(n/b) + f(n)."""
costs = []
j, size = 0, n
while size > 1:
costs.append(a**j * f(size))
size //= b
j += 1
return costs, a**j
for a in (8, 4, 2):
costs, leaves = level_costs(a, 2, lambda m: m * m, 64)
print(a, costs, "leaves:", leaves)
# 8 [4096, 8192, 16384, 32768, 65536, 131072] leaves: 262144
# 4 [4096, 4096, 4096, 4096, 4096, 4096] leaves: 4096
# 2 [4096, 2048, 1024, 512, 256, 128] leaves: 64With a = 8, each level doubles and the leaves outweigh everything above them. With a = 4, every level costs 4096, and there are log_2 64 = 6 levels plus a leaf level of the same size. With a = 2, each level halves, so the root's 4096 makes up about half the total.
The real theorem allows any f(n), not only exact powers, so each case needs its own short argument. The arguments below follow the pattern in the table.
Case 1: An Increasing Series Is Dominated by Its Last Term
Suppose f(n) = O(n^(c−ε)) for some ε > 0. Then the cost of level j is at most a constant times
a^j·(n/b^j)^(c−ε) = n^(c−ε)·(a/b^(c−ε))^j = n^(c−ε)·(b^ε)^j.
The last step uses a = b^c. Summing over j from 0 to (log_b n) − 1:
g(n) = O(n^(c−ε)·((b^ε)^(log_b n) − 1)/(b^ε − 1)) = O(n^(c−ε)·n^ε) = O(n^c).
An increasing geometric series is within a constant factor of its largest term, which here is the level just above the leaves. So g(n) is no larger than the leaf cost, and T(n) = Θ(n^c).
The ε matters. You need a polynomial gap so that the ratio b^ε is a constant strictly greater than 1. If the gap is only a log factor, the series is not geometric and this argument fails.
Case 2: A Flat Series Is Its Term Times the Number of Terms
Suppose f(n) = Θ(n^c). Then the cost of level j is
Θ(a^j·(n/b^j)^c) = Θ(n^c·(a/b^c)^j) = Θ(n^c).
Every one of the log_b n internal levels costs Θ(n^c), so g(n) = Θ(n^c log n). That outweighs the leaf term by a factor of log n, which gives T(n) = Θ(n^c log n).
The extended case 2 uses the same calculation. If f(n) = Θ(n^c·log^k n) with k ≥ 0, the cost of level j becomes Θ(n^c·(logb n − j)^k). As j runs from 0 to logb n − 1, the value m = logb n − j runs from logb n down to 1, so
g(n) = Θ(n^c·sum over m = 1 to log_b n of m^k) = Θ(n^c·log^(k+1) n).
The sum of m^k up to L is Θ(L^(k+1)). That fact explains the extra log factor in the extended case.
Case 3: A Decreasing Series Is Dominated by Its First Term
Suppose a·f(n/b) ≤ k·f(n) for some constant k < 1 and all large enough n. This is the regularity condition. Apply it j times:
a^j·f(n/b^j) ≤ k^j·f(n).
Each level costs at most k times the level above it, so
g(n) ≤ f(n)·(1 + k + k^2 + ...) = f(n)/(1 − k) = O(f(n)).
The root term alone already gives g(n) ≥ f(n), so g(n) = Θ(f(n)). The condition f(n) = Ω(n^(c+ε)) then makes f(n) larger than the leaf term n^c, and T(n) = Θ(f(n)).
For f(n) = n^d with d > c, regularity holds automatically: a·(n/b)^d = (a/b^d)·n^d, and a/b^d < 1. Polynomial-times-log functions also satisfy it for large n. That is why the master_theorem helper from the earlier chapter never needs to check regularity for inputs of that form.
What the Proof Tells You About the Gaps
The proof also shows why some recurrences fit no case. The cases need the level costs to grow geometrically, stay flat, or shrink geometrically. If f(n) is close to n^c but differs from it by a non-polynomial factor, the level costs change too slowly to form a geometric series, and they are not flat either. You can still sum the tree directly, which is what the first exercise below asks you to do.
| Case | Shape of level costs | Key tool in the proof | Hypothesis that makes it work |
|---|---|---|---|
| 1 | increasing geometric | sum ≈ last term | polynomial gap ε below n^c |
| 2 | constant | term × number of levels | f(n) = Θ(n^c) |
| 2 extended | slowly decreasing polynomial in m | sum of m^k is Θ(L^(k+1)) | f(n) = Θ(n^c log^k n) |
| 3 | decreasing geometric | sum ≈ first term | regularity a·f(n/b) ≤ k·f(n) |
Exercise
Use the recursion-tree sum to solve T(n) = 2T(n/2) + n/log2 n for n a power of 2. Explain why no master theorem case applies.
Show answer
Here c = log_2 2 = 1. Level j costs 2^j·(n/2^j)/log2(n/2^j) = n/(log2 n − j). With m = log2 n − j running from 1 to log2 n, g(n) = n·(1 + 1/2 + ... + 1/log2 n) = n·H(log2 n) = Θ(n log log n). The leaves cost Θ(n), so T(n) = Θ(n log log n). Case 1 does not apply because n/log n is smaller than n by only a log factor, not by a polynomial factor n^ε. Case 2 does not apply because n/log n is not Θ(n), and the extended case 2 needs k ≥ 0, while here k = −1. Case 3 does not apply because f is smaller than n^c.
Exercise
Prove the leaf-count identity a^(logb n) = n^(logb a).
Show answer
Take log base b of both sides. The left side gives logb n · logb a. The right side gives logb a · logb n. The two are equal, and log_b is one-to-one, so the original quantities are equal.
Exercise
For T(n) = 3T(n/4) + n log n, find c, show that the regularity condition holds for large n, and state the result.
Show answer
c = log_4 3 ≈ 0.793, and f(n) = n log n = Omega(n^(c+eps)) with eps ≈ 0.2. Regularity: 3·(n/4)·log(n/4) ≤ (3/4)·n log n, so k = 3/4 < 1 works for all n ≥ 4. Case 3 gives T(n) = Theta(n log n).