Most people learn the Master Method as a lookup table: compare to , pick one of three cases, done. The table works, but it's not understood; it's recited. The moment you meet a recurrence that doesn't fit neatly into the memorized shape, the table is useless.
The fix is to never memorize the table at all. Build a recursion tree for the general recurrence
count the work level by level, and let a single geometric series, built the exact way Tim Roughgarden derives it, tell you which of the three cases you're in and why. Once you've done this once by hand, the "three cases" stop feeling like three separate facts and become one picture viewed from three different angles.
Step 1: Build the tree, one level at a time
At the root (level 0), there is exactly one call, operating on an input of size
, doing
work outside of its recursive calls.
Level 0: [ n ] work = n^d
That call makes
recursive calls, each on a subproblem of size
. That's level 1:
Level 0: [ n ] work = n^d
Level 1: [n/b] [n/b] ... [n/b] (a of them) work = a·(n/b)^d
The row work already tells you something important: going from level 0 to level 1, the work got multiplied by (more subproblems) and divided by (each subproblem cheaper). Whether the total work grows or shrinks as you go deeper depends entirely on which of those two effects is bigger.
Step 2: The general formula for row j
Generalize the pattern. At level (counting down from the root, which is level 0):
- Number of nodes: each node spawns children, so level has nodes.
- Size per node: the input has been divided by , times, so each node holds a subproblem of size .
- Work per node: .
Multiplying nodes by work-per-node gives the total work at level , call it :
Define . This single number is the ratio between consecutive rows of the tree: it is the whole Master Method compressed into one variable. is the rate at which subproblems multiply going down the tree; is the rate at which the work per subproblem shrinks. is simply which of those two effects wins.
Step 3: Total work is a geometric series
The tree bottoms out when a subproblem reaches size 1, i.e., when , giving levels. Summing the row work over every level from the root to the leaves:
This is exactly a geometric series, a sum of a constant ratio raised to increasing powers, and its behavior is fully determined by the closed-form geometric sum formula:
Everything from here is just plugging in and reading off what dominates.
Case 1: r is less than 1, the sum is bounded by a constant and dominated by the first term
If , then . Rewrite the geometric sum for this case as:
Since
, the term
shrinks toward 0 as
grows; it never grows, no matter how deep the tree is. The entire sum is therefore bounded above by the constant
, regardless of how many levels the tree has. The geometric series doesn't blow up with depth. It converges, and the term that matters is the first term of the series (the root), because every later term is a shrinking fraction of it.
Level 0: [ n ] work = n^d
Level 1: [n/b] work = r · n^d
Level 2: [n/b²] work = r² · n^d
⋮ ⋮ (shrinking geometrically)
Conclusion: since the sum is a constant multiple of the root's work, the total cost of the tree is dominated by the root, giving .
Case 2: r equals 1, every term is equal and the sum is just the level count
If
, then
, and the geometric sum formula degenerates to
, the number of levels. Every row contributes exactly
, with no growth and no decay:
Level 0: [ n ] work = n^d
Level 1: [n/b] ... [n/b] work = n^d
Level 2: [n/b²] ... [n/b²] work = n^d
⋮ ⋮ (flat)
Conclusion: since there are levels, each contributing , the total is .
Case 3: r is greater than 1, the sum is dominated by the last term
If , then . Now the geometric sum
grows without bound as grows. Crucially, it is dominated by its largest term, which is the final term of the series, , not the first one. This is the mirror image of Case 1: when , each successive term is larger than the one before it by a factor of , so the sum is within a constant factor of its biggest term. Pulling out of every term in the sum:
since
, that inner sum falls back into Case 1's bounded regime: it's just some constant. So the total work is dominated by the last level of the tree, the leaves, not the root.
Level 0: [ n ] work = n^d
Level 1: [n/b] [n/b] [n/b] [n/b] work = r · n^d
Level 2: [n/b²] × a² work = r² · n^d
⋮ ⋮ (growing geometrically)
Level k: [1] × a^k work = r^k · n^d ← dominant term
Don't leave that dominant term as ; simplify it all the way down. Recall , which means . Substitute and expand step by step:
Now use to collapse the fraction:
So the dominant term is just , plain and simple: the number of leaves. Substituting back in, and using the identity that swapping the base and the exponent of a power-of-a-log leaves the value unchanged,
Conclusion: since the sum is dominated by the leaf level, and that leaf-level term simplifies to exactly , .
Why that exponent is exactly the leaf count
That final expression, , isn't an arbitrary algebra trick. It is, literally, the number of leaves in the tree. The derivation above showed exactly that: the dominant term collapsed to , the leaf count, and rewriting as turned that leaf count into .
So in Case 3, when the tree's total cost is dominated by its bottom row, what you're really computing is "how many leaves does this tree have?", and the answer to that question, , is the running time. The formula isn't describing some abstract growth rate. It's counting boxes at the bottom of the picture you already drew.
Worked example: fixing b and d, varying only a
To see all three cases as one continuous family, fix and (so the base recurrence is ) and vary only .
. . Row work shrinks geometrically: . Bounded by the root. .
. , merge sort. Row work is flat: across levels. .
. . Row work grows geometrically: , dominated by the leaves. Leaf count is . .
Same , same , same tree-building process; only the value of changed, and the geometric series formula did the rest of the work.
The cheat sheet, now with the reasoning attached
| Compare | Ratio | Geometric sum behavior | Dominant term | Total cost |
|---|---|---|---|---|
| bounded by a constant | first term (the root) | |||
| exactly equal terms | every level equally | |||
| grows; dominated by | last term (the leaves) | , i.e. the leaf count |
The "compare to " rule isn't three unrelated facts to memorize. It's one geometric series, the sum of , being read in the only three ways a geometric series can behave: shrinking to a constant, staying flat, or exploding toward its final term. And in that last, exploding case, the scary-looking exponent is nothing more than the plain count of leaves at the bottom of the tree. Once that's internalized, no recurrence outside the textbook table needs to be scary again. Draw three rows, work out , and the geometric sum formula tells you exactly where the weight of the tree sits.
Top comments (0)