Introduction
The running time of a recursive algorithm is naturally described by a recurrence: an equation that gives in terms of on smaller inputs. Merge sort splits an array into two halves, sorts each and merges in linear time, so . Solving the recurrence means finding a closed-form asymptotic bound, here .
This note covers the four standard methods: substitution, recursion trees, the master theorem, and unrolling for subtract-type recurrences, together with change of variables and the cases where the master theorem does not apply.
Prerequisites
- Asymptotic Notation: , , , polynomial versus logarithmic growth.
- Recurrence Relations: exact solution of linear recurrences such as .
- Geometric series: is for , for , and for .
Core concepts
Conventions
- is a running time, so it is positive, and for all below some constant. The base case is usually omitted because it changes the solution by at most a constant factor.
- Floors and ceilings () are usually dropped; for the recurrences treated in this note they do not change the asymptotic answer (CLRS 3e, Section 4.6 justifies this for the master recurrence).
- . The critical exponent of the master recurrence is ; for example and .
Method 1: substitution (guess and prove by induction)
- Guess the form of the solution (from a recursion tree or experience).
- Prove it by induction on , finding constants that make the inductive step work.
Example: . Guess . Assume it for . Then
The base case is handled by choosing and large enough (start the induction at rather than , since ).
Two pitfalls.
- The inductive step must give exactly the hypothesis. Trying to prove for the same recurrence gives , which is not for any constant . Writing ", done" is a wrong proof.
- Subtract a lower-order term when the guess is right but the induction fails. For , the guess gives , which fails. The stronger guess gives whenever . So .
Method 2: the recursion tree
Draw the tree of recursive calls. Each node is labelled with the non-recursive cost of its call; sum each level, then sum the levels.
For :
- Level (root is level 0) has nodes, each of size , costing in total.
- The tree has levels below the root, and the bottom level has leaves, each costing .
Example: . Every level costs ( nodes of cost ), there are levels, so .

Unequal splits. For , each full level still costs , but the tree is lopsided: the shortest root-to-leaf path has length and the longest . Summing gives at most and at least , so . The master theorem does not apply here, because the subproblems have different sizes.

A useful rule follows from the same argument. If with fixed constants , suitable integer rounding and a terminating constant-size base case, then the costs of full levels form a geometric series with ratio .
Partial levels cannot exceed the corresponding full-level cost. With shrinking fractions, the shallowest and deepest leaves both have depth ; for , the full levels give the lower bound, and all levels together give . For , summing the full-level upper bounds gives , while the root gives .
| Solution | |
|---|---|
| , for example () | |
| , for example |
For the answer is a power with defined by ; for equal splits this is the master theorem's .
Method 3: the master theorem
Master theorem (CLRS 3e, Section 4.5). Let and be constants, let be an asymptotically positive function, and let be defined on the non-negative integers by
where may be read as or . Compare with the watershed function :
- If for some constant , then .
- If , then .
- If for some constant , and if for some constant and all sufficiently large (the regularity condition), then .
Interpretation through the recursion tree: in case 1 the leaves dominate (level costs grow geometrically downwards); in case 2 all levels cost the same; in case 3 the root dominates (level costs shrink geometrically).

Notes on the conditions.
- "Polynomially smaller" (case 1) and "polynomially larger" (case 3) mean by a factor . A logarithmic factor is not enough: is larger than but not polynomially larger.
- For polynomial with , regularity holds automatically: and . So the condition matters only for unusual .
- The regularity condition can fail. Take , , . Then , so the first part of case 3 holds, but for infinitely many even () , and the ratio comes arbitrarily close to . No constant works, and case 3 cannot be used.
Extended case 2 (CLRS 3e, Exercise 4.6-2). If for a constant , then . Case 2 is the special case . This covers , which falls in the gap between cases 2 and 3 of the basic theorem.
Related material: the table. A wider version is often stated for with constants and real . It is not a CLRS theorem, but each row follows from the recursion tree (level costs times ):
| Relation of and | Condition on | |
|---|---|---|
| any | ||
| any |
With every level contributes of a shrinking argument, so the sum is up to constants: a power sum for , a harmonic sum for , and a convergent series for . For example . Some books write for , ; that is only an upper bound, since the root alone already costs .
When the master theorem does not apply
| Recurrence | Why not | Solution and method |
|---|---|---|
| larger than only by | , extended case 2 or recursion tree | |
| smaller only by | , recursion tree (harmonic sum of level costs) | |
| unequal subproblem sizes | , recursion tree | |
| is not a constant | not polynomial; unroll | |
| subtractive, no | , unrolling | |
| argument is not | , change of variables | |
| by recursion tree; the theorem needs |
Method 4: unrolling subtract-type recurrences
For recurrences that reduce by a constant, expand repeatedly and sum.
- : (linear recursion, for example recursive linear search).
- : (for example selection sort written recursively, or quicksort's worst case).
- , : exactly (Tower of Hanoi moves).
- , : , , where is the Fibonacci sequence (naive Fibonacci call count).
- General bound: if with constants , and , then when and when .
Change of variables
For , put , so and . Define . Then , which is case 2: . Translating back, . Similarly gives , so .
Worked examples
| Recurrence | Comparison with | Solution | |
|---|---|---|---|
| (merge sort) | equal: case 2 | ||
| (binary search) | equal: case 2 | ||
| (naive block matrix multiply) | smaller by : case 1 | ||
| (Strassen) | smaller by : case 1 | ||
| (tree traversal) | smaller by : case 1 | ||
| larger by ; regularity , : case 3 | |||
| larger by more than ; regularity : case 3 | |||
| : extended case 2, | |||
| smaller by : case 1 | |||
| equal: case 2 |
Exact values check the asymptotics. With and :
- gives (for : 11264).
- gives .
- gives .
Recurrence from code
F(n)
if n <= 1 then return 1
s <- 0
for i <- 1 to n
for j <- 1 to n
s <- s + 1
return F(n/2) + F(n/2) + F(n/2) + F(n/2) + sFour calls on plus increments: , case 2, . Counting only the increments of s, with none for , the exact total is for (1,024 for ).
Replacing the return line by return 4 * F(n/2) + s computes the same value with one call: , and the increments total (84 for , 340 for ). The number of recursive calls in the code, not the arithmetic in the formula, sets .
Important properties and observations
- The master theorem compares with polynomially; logarithmic differences fall into gaps.
- The base of the logarithm in matters (it is the exponent); the base of in the case 2 answer does not.
- The theorem gives , so it gives both an upper and a lower bound. If is given only as , a matching toll-driven lower bound may be unavailable. However, case 1 still gives for a nonnegative toll and a positive constant base cost, because the leaves supply that lower bound.
- Adding a constant to an argument requires a terminating cutoff: for , choose a constant base-case cutoff , with rounding handled so recursive arguments shrink above it. Then the solution is . For example, floor rounding with integer works. An arbitrary unchanged small base case may not terminate: 34 maps to itself. is still .
- In a substitution proof, never absorb the error term with inside the induction; carry the explicit constant.
GATE examination perspective
- Direct application. identify , , , compute , decide the case, and check regularity for case 3 when is not a polynomial.
- Recurrence from code. write the recurrence first (how many recursive calls, of what size, plus the non-recursive work), then solve it. A function that calls itself twice on is exponential, not quadratic.
- Traps.
F(n/2) + F(n/2)is two calls but2 * F(n/2)is one; is not ; is , not ; is not covered by the master theorem; unequal splits need a recursion tree; needs a change of variables. - Exact answers. when asked for a value (for example, the number of moves or calls), solve the recurrence exactly, not asymptotically.
Summary
Sources
- T. H. Cormen, C. E. Leiserson, R. L. Rivest, C. Stein, Introduction to Algorithms, 3rd ed., MIT Press, 2009, Chapter 4, Sections 4.3 (substitution method), 4.4 (recursion-tree method), 4.5 (the master method and the master theorem) and 4.6 (proof of the master theorem; Exercise 4.6-2, the extended case 2).