Algorithms · Master Theorem and Solving Recurrences: All Cases and Traps
What a Recurrence Is and Why We Solve It
This chapter takes you from "what is a recurrence" to the exact, exam-ready mastery of the Master Theorem — every case, the extended case 2, the situations where the theorem silently fails, twelve fully worked recurrences, the substitution method with its classic wrong-proof trap, and the change-of-variable trick. Every arithmetic step is shown and rechecked.
A recurrence expresses the cost T(n) of an algorithm on input size n in terms of its cost on smaller inputs. For divide-and-conquer algorithms the standard shape is
T(n)=aT(n/b)+f(n)
with symbols defined as:
Symbol
Meaning
Constraint
n
size of the (sub)problem
n>0
a
number of recursive subproblems
a≥1, constant
b
factor by which input shrinks
b>1, constant
f(n)
cost of dividing + combining (the "non-recursive" work)
f(n)≥0
The critical exponent is
p=logba=lnblna.
This single number p is the whole game: the Master Theorem compares f(n) against np.
The Master Theorem — All Three Cases
Let T(n)=aT(n/b)+f(n), a≥1, b>1, and p=logba.
Case 1 — leaves dominate (recursion dominates)
If f(n)=O(np−ε) for some constant ε>0, then
T(n)=Θ(np)=Θ(nlogba).
Intuition: the combine work is polynomially smaller than the leaf work, so the leaves (there are alogbn=nlogba of them) dominate.
Case 2 — balanced (all levels cost the same)
If f(n)=Θ(np), then
T(n)=Θ(nplogn)=Θ(nlogbalogn).
Intuition: every one of the logbn levels costs the same Θ(np), so multiply by the number of levels.
Case 3 — root dominates (combine dominates)
If f(n)=Ω(np+ε) for some ε>0AND the regularity condition holds:
af(n/b)≤cf(n)for some constant c<1 and all sufficiently large n,
then
T(n)=Θ(f(n)).
Intuition: the top-level combine work is so large it swamps everything below; the regularity condition guarantees the geometric series of combine costs converges.
The regularity condition — what it really checks
For a polynomial f(n)=nq, the regularity condition becomes
a(bn)q≤cnq⟺bqa≤c<1⟺a<bq⟺q>logba=p.
So for polynomial f, Case 3's Ω condition and the regularity condition are the same statement (q>p). The regularity condition only needs separate checking when f is not a clean polynomial (e.g. f(n)=n2/logn or f(n)=n2sin2n). In GATE, f is almost always polynomial, so "Case 3 applies" ⇔ "f grows polynomially faster than np."
Extended Case 2 (the logkn refinement)
When f(n)=Θ(nplogkn) for a constant k≥0:
T(n)=Θ(nplogk+1n).
This is the "polylog" extension. The three sub-cases people quote:
f(n)
Result
Note
Θ(nplogkn), k>0
Θ(nplogk+1n)
one extra log
Θ(nplog0n)=Θ(np)
Θ(nplogn)
ordinary Case 2 (k=0)
Θ(np/logn) i.e. k=−1
Θ(nploglogn)
"one log less"
Θ(np/logkn), k>1
Θ(np)
extended (Akra–Bazzi) result; classical Case 1 does not apply
Careful with the k=−1 and k<−1 rows. These are not part of the classical Master Theorem; they come from the Akra–Bazzi / extended treatment. The clean, safe statement for exams: if f(n)=np/logn, the answer is Θ(nploglogn); if f(n)=np/logkn with k>1, the answer is Θ(np) (this follows from Akra–Bazzi; classical Case 1 does not apply, because np/logkn is notO(np−ε) for any ε>0). GATE rarely tests k=−1 directly, but know it exists.
When the Master Theorem Does NOT Apply
The theorem has hypotheses. Break any one and you must fall back on substitution / recursion tree. GATE loves these.
Failure
Example
Why it fails
What to do
a<1 (not a valid branching count)
T(n)=21T(n/2)+n
a=21<1; not a real algorithm
substitution: T(n)=Θ(n)
a not constant
T(n)=nT(n/2)+n
a depends on n
expand: T(n)=2Θ(log2n) (super-polynomial); use tree
b not constant / b≤1
T(n)=2T(n/2)+n is fine, but T(n)=2T(n)+1 has b=n
shrink factor is not constant
change of variable
Non-polynomial gap
T(n)=2T(n/2)+n/logn
f=n/logn is o(n) but notO(n1−ε) for any ε>0
extended / substitution → Θ(nloglogn)
f negative somewhere
T(n)=2T(n/2)−n
f(n)≥0 violated
not a cost recurrence; handle directly
f oscillating
f(n)=n2sin2n
regularity condition may fail
check regularity explicitly
The non-polynomial gap is the #1 GATE trap.n/logn sits betweenn0 and n1 but is not polynomially separated from n1: for every ε>0, n/logn=O(n1−ε). So Case 1 does not apply even though f is "smaller" than n. The correct answer for 2T(n/2)+n/logn is Θ(nloglogn) (extended case, k=−1).