On this page
A divide-and-conquer algorithm splits a problem of size n into a pieces of size n/b, solves each piece the same way, and spends f(n) work splitting and combining. Its running time obeys the recurrence T(n) = aT(n/b) + f(n). The master theorem turns that line into a Θ bound with one comparison.
Jon Bentley, Dorothea Haken (now Dorothea Blostein) and James Saxe published the method in 1980 as a general method for solving divide-and-conquer recurrences in ACM SIGACT News. The textbook Introduction to Algorithms later popularised the name "master theorem", according to the Wikipedia article on the theorem).
What does the master theorem say?
Fix constants a ≥ 1 and b > 1, and call p = log_b a the critical exponent. The three cases) compare f(n) with n^p:
Case 1: if f(n) = O(n^c) for some c < p, then T(n) = Θ(n^p). The leaves of the recursion win.
Case 2: if f(n) = Θ(n^p (log n)^k) for some k ≥ 0, then T(n) = Θ(n^p (log n)^(k+1)). Every level costs the same, so you gain one log.
Case 3: if f(n) = Ω(n^c) for some c > p, and a·f(n/b) ≤ k·f(n) for some constant k < 1 and all large n (the regularity condition), then T(n) = Θ(f(n)). The root wins.
In Cases 1 and 3, f(n) must differ from n^p by a power of n, not just by a log.
Why does comparing f(n) with n^(log_b a) work?
Draw the recursion tree. Level i has a^i nodes, each a problem of size n/b^i, so that level costs a^i f(n/b^i). The tree is log_b n levels deep and has a^(log_b n) = n^p leaves.
Take f(n) = n^c. Then level i costs n^c (a/b^c)^i, a geometric series with ratio r = a/b^c. If r > 1 (that is, c < p), the costs grow towards the bottom and the leaves dominate: Case 1. If r = 1, all log_b n levels cost n^c, giving n^c log n: Case 2. If r < 1, the costs shrink and the root's f(n) dominates: Case 3.
How does the master theorem solve merge sort, Karatsuba and Strassen?
The first two examples are in the master theorem article's table of common algorithms).
Merge sort: T(n) = 2T(n/2) + Θ(n). Here p = log_2 2 = 1 and f(n) = n^1, so Case 2 with k = 0 gives Θ(n log n).
Binary search: T(n) = T(n/2) + Θ(1). Here p = log_2 1 = 0 and f(n) = n^0, so Case 2 gives Θ(log n).
Karatsuba multiplication: Anatoly Karatsuba found in 1960 that two n-digit numbers can be multiplied with three products of n/2-digit numbers instead of four, as the Karatsuba algorithm article records. So T(n) = 3T(n/2) + Θ(n). Now p = log_2 3 ≈ 1.585 > 1, so Case 1 gives Θ(n^(log_2 3)), about n^1.585. With four products, p = log_2 4 = 2 and you are back to the schoolbook n².
Strassen's matrix multiplication: Volker Strassen's 1969 paper Gaussian elimination is not optimal uses 7 products of half-size blocks instead of 8 (Strassen algorithm article). Block additions cost Θ(n²), so T(n) = 7T(n/2) + Θ(n²). Since p = log_2 7 ≈ 2.807 > 2, Case 1 gives Θ(n^(log_2 7)), about n^2.807, against n³ for 8 products.
Karatsuba and Strassen share one idea: saving one recursive call lowers a, which lowers p. That is the whole speed-up.
When does the master theorem not apply?
The master theorem article) lists recurrences it cannot solve:
a is not a constant: T(n) = 2^n T(n/2) + n^n.
The gap is only a log: T(n) = 2T(n/2) + n/log n sits between Case 1 and Case 2. An extended Case 2 gives Θ(n log log n).
f(n) is not positive: T(n) = 64T(n/8) − n² log n.
Regularity fails: T(n) = T(n/2) + n(2 − cos n).
Unequal pieces, such as T(n) = T(n/3) + T(2n/3) + n, are outside the form too; use a recursion tree or the Akra-Bazzi method, which the same article names as a generalisation. For T(n) = T(n − 1) + n, just add the levels: n + (n − 1) + ... + 1 = Θ(n²).
A four-step check for any recurrence
Read off a, b and f(n). Check that a ≥ 1 and b > 1 are constants and f(n) is positive.
Compute p = log_b a.
Compare f(n) with n^p: smaller by a power of n, equal up to a log factor, or larger by a power of n.
In Case 3, check regularity. If nothing fits, draw the tree and sum the levels.
Practise on three recurrences with p = 2: 4T(n/2) + n gives Θ(n²) (Case 1); 4T(n/2) + n² gives Θ(n² log n) (Case 2); 4T(n/2) + n³ gives Θ(n³) (Case 3).
If the tree or the logarithms keep slipping, the Fermi Concept Library covers every concept in mathematics and computing, and the Fermi Problem Library has a step-by-step solver that explains the reasoning rather than printing an answer.
Next, try sorting networks and the 0-1 principle, circulant matrices, the DFT and the FFT or asymptotic expansions.



