Start from foundations · Course contents · فارسی
Previous lesson: Recursion from scratch: from function calls to cost recurrences
The Master method from scratch: levels, leaves and local work
In the previous lesson, we counted a recursion tree level by level. If equal-sized subproblems occur repeatedly, must we redraw every tree? The Master method turns that counting into a procedure for a specific family of recurrences. First verify membership in that family: memorizing three answers without their conditions is insufficient.
Objective: separate child count, child size and local work; apply the power-function version correctly; recognize when it does not apply. Cost recurrences, Θ notation and logarithms from the previous two lessons are prerequisites. This is an introductory method; general proofs, extended versions and amortized analysis remain future topics.
1. What the recurrence says
The target form is:
T(n) = a T(n/b) + f(n)
T(1) = Θ(1)
T(n) is total cost, a counts subproblems, b is the size-reduction factor, and f(n) includes all work outside the child calls. Solving two halves and then reading every element once gives a=2, b=2, f(n)=Θ(n). Include that reading in f, without counting the children's entire execution there again.
Here a is a fixed integer at least one, b is fixed and greater than one, and costs are nonnegative. For transparent counting, take integer b and let n be a power of b, making division exact. Rounding belongs to a broader treatment. The child count must not depend on n: n T(n/2) violates these assumptions.
2. Where the leaf count comes from
After h divisions by b, a subproblem has size n/b^h. Reaching one requires b^h=n, so height is h=log_b(n). If each node has a children, level zero has one node, level one has a, and level i has a^i. At the base level:
leaves = a^h = a^(log_b(n)) = n^(log_b(a))
p = log_b(a)
The constant p expresses leaf count as a power of n. For a=3,b=3, p=1: input nine gives nine leaves. For a=4,b=2, p=2. There need not be two children or an exponent of one.
This illustrates T(n)=3T(n/3)+n with unit base cost at n=9: two non-base levels costing nine each and nine leaves, totaling twenty-seven. One pictured size does not establish a general law; we build the level sum below.
3. The power-function version and its three cases
This lesson's version requires f(n)=Θ(n^k) for fixed k>=0. That restriction makes application straightforward. Logarithmic factors or irregular growth require more than this table. The Cornell Master-method notes state the more general conditions.
At level i, there are a^i nodes of size n/b^i, giving level work on the order of:
n^k (a/b^k)^i
r = a/b^k
The ratio r describes successive level costs. Since a=b^p, comparing k with p determines whether r is above, equal to or below one.
| Comparison | Level-cost pattern | Total cost |
|---|---|---|
| k < p | Increases downward; the leaf region dominates | Θ(n^p) |
| k = p | Same order at every level; logarithmically many levels | Θ(n^p log n) |
| k > p | Decreases downward; the root dominates | Θ(n^k) |
Why not multiply by height in the first case? The levels are not equally costly. When cost increases by a fixed factor greater than one, the geometric sum is within a constant factor of its last term: 1+2+4+...+m is less than 2m. The third case uses the same argument from the root. Only the equal case adds log n comparable levels. Constant-cost leaves are included in these totals.
4. Three worked examples without skipped steps
Example one: T(n)=4T(n/2)+n. Four half-sized children give p=log₂(4)=2; local work has k=1. Since 1<2, total cost is Θ(n²). Root work is n, next-level work is 4*(n/2)=2n, then 4n: increasing node count outweighs decreasing node size.
Example two: T(n)=3T(n/3)+5n. Here p=1,k=1. The factor five does not change the exponent. Each non-base level contributes 5n; there are log₃(n) such levels and linear leaf cost. The result is Θ(n log n). With unit base cost and n=9, exact cost is 5*9*2+9=99. A growth-class table does not supply exact counts.
Example three: T(n)=3T(n/3)+n². Now p=1,k=2, yielding Θ(n²). The decrease is explicit: next-level work totals 3*(n/3)²=n²/3, followed by n²/9. Their sum stays within a constant factor of n². In the general theorem, this kind of decrease corresponds to a regularity condition. Merely being “larger” is insufficient for arbitrary local-work functions.
5. When to put the table aside
T(n)=T(n-1)+n reduces size by subtraction, not division by a constant, so it is outside this form. Expanding to the base yields 1+2+...+n, giving Θ(n²). One tool's inapplicability does not make a recurrence unsolvable.
In T(n)=T(n/3)+T(2n/3)+n, child sizes differ. Replacing them without justification by 2T(n/3) changes the problem. Our table does not apply directly.
A subtler example is T(n)=2T(n/2)+n log₂(n). Although p=1, local work is not Θ(n): the logarithmic factor grows. For n=2^h, level i costs n(h-i). Summing non-base levels gives n(h+(h-1)+...+1)=n h(h+1)/2; leaves add Θ(n). Thus total cost is Θ(n(log n)²). This comes from summing levels, rather than forcing the recurrence into our simple table.
6. Independent practice and test tips
All questions are original. Identify a,b,f,p before opening an answer.
1. What is the tight bound for T(n)=8T(n/2)+n² with constant base cost?
Answer 1
a=8, b=2, p=3 and k=2. Since k<p, the result is Θ(n³). Leaf count grows faster than root-local work.
2. Does T(n)=2T(n/4)+n have logarithmic cost because there are few children relative to the size divisor?
Answer 2
No. p=log₄(2)=1/2 and k=1. Root work dominates, giving Θ(n). Two children alone do not determine total growth.
3. Original multiple choice: For T(n)=9T(n/3)+7n², choose the tight bound. A) Θ(n²); B) Θ(n² log n); C) Θ(n³); D) Θ(log n).
Test answer
B. p=log₃(9)=2 and k=2. Equal-order levels add a log n factor. Seven is a constant coefficient.
4. Why can we not assign a=1,b=1 to T(n)=T(n-1)+1?
Answer 4
n−1 is not n/b for constant b; b=1 would not shrink the input and violates b>1. Expansion gives n constant-cost steps and Θ(n) total cost.
5. Transfer: With T(n)=3T(n/3)+n and T(1)=2, what is the exact cost at n=9? Does changing the base cost from one to two change its growth class?
Answer 5
The root costs 9, the next level costs 9, and nine leaves cost 2 each: total 36. Changing a constant leaf coefficient changes the exact value but not Θ(n log n) growth.
7. Retrieve and decide whether to continue
Without looking, explain where height comes from, why there are n^p leaves, and which case needs adding comparable levels. If case selection fails, calculate the first two level costs. If the recurrence shape is unsuitable, change tools and expand it. Explaining both conditions and conclusions is a practical continuation criterion. Try fresh a,b values after a gap.
References and authorship
Source checked on 2026-11-23: Cornell CS3110: Recursion Trees and the Master Method, for the recurrence form and general conditions. This lesson teaches a restricted power-function version with original explanations, diagrams and exercises; it does not republish the source text.
Prerequisite: recursion and cost recurrences · Course contents · Start from foundations
Previous lesson: Recursion from scratch: from function calls to cost recurrences