The Master Theorem [00PY]
- October 23, 2026
Adding up the total work in a recursion tree for divide-and-conquer algorithms can be generalized to a powerful theorem known as the Master Theorem. (It is not named for someone; it is just a powerful theorem that "masters" a very wide range of divide-and-conquer algorithms. This is especially true when considering its generalizations such as the Akra-Bazzi method.)
Theorem Master Theorem [00Q1]
- October 23, 2026
If T(n) = a T(n/b) + \Theta (n^d) for positive constants a, b, and d, then T(n) = \begin {cases} \Theta (n^d) & \text {if } a < b^d \\ \Theta (n^d \log n) & \text {if } a = b^d \\ \Theta (n^{\log _b a}) & \text {if } a > b^d. \end {cases}
Remark Master theorem intuition [00Q5]
- October 23, 2026
Intuitively, a tells us how fast the number of recursive calls grows; b^d tells us how fast the problems are getting smaller. The ratio of these will end up being the common ratio of a geometric sum.
- If a < b^d, then the problems get smaller faster than the number of problems increases, and the total amount of work is dominated by the work done at the very top of the recursion tree.
- If a > b^d, then the number of nodes is growing faster than the work decreases, so the amount of work is dominated by the bottom level of the tree (as in our integer multiplication example).
- If a = b^d, then the growth of the number of subproblems is exactly balanced by the decrease in the amount of work, so there is exactly the same amount of work done in total at each level of the recursion tree (namely, O(n^d)), and the overall total is hence this amount of work per level times the number of levels (as in merge sort).
Remark Master theorem generalizations [00Q6]
- October 23, 2026
The Master Theorem can be generalized in a number of ways (for example, T(n) can be less than or equal to the right-hand side instead of equal; we can handle more complex expressions for the amount of extra work besides just \Theta (n^d); n need not be evenly divisible by b; and so on). I have presented the simple core of the idea here, and if you were to ever need a generalized version for some reason, you could look it up.
Before we get to the proof of the theorem itself, we will need a few small lemmas.
Lemma Log powers [00PZ]
- October 23, 2026
For any real numbers a,b > 1 and x > 1, a^{\log _x b} = b^{\log _x a}.
Proof.
- October 23, 2026
Lemma Asymptotic behavior of geometric series [00Q0]
- October 23, 2026
For some positive real constant r and any natural number n, let S = 1 + r + r^2 + \dots + r^n.
- If 0 < r < 1, then S is \Theta (1).
- If r = 1, then S is \Theta (n).
- If r > 1, then S is \Theta (r^n).
Proof.
- October 23, 2026
- If r < 1, then the infinite sum 1 + r + r^2 + \dots converges to the constant value \frac {1}{1-r}. The partial sum up to k is less than this, so it cannot depend on n either.
- If r = 1, then S = 1 + 1 + 1 + \dots + 1 = n+1, which is \Theta (n).
- If r > 1, then S = \frac {1 - r^{n+1}}{1 - r} = r \cdot r^n + \frac {1}{r-1} which is \Theta (r^n).
Proof of the Master Theorem [00Q7]
- October 23, 2026
We now have the tools we need to prove the Master Theorem.
Proof.
- October 23, 2026
- The tree has height \log _b n.
- A node at level k has size n/b^k and does (n/b^k)^d work.
- There are a^k nodes at level k, so the total work at level k is a^k \cdot \left (\frac {n}{b^k}\right )^d = n^d \left (\frac {a}{b^d}\right )^k.
Hence the overall total work is \sum _{k=0}^{\log _b n} n^d \left (\frac {a}{b^d}\right )^k = n^d \sum _{k=0}^{\log _b n} \left (\frac {a}{b^d}\right )^k. This is n^d times a geometric series with ratio a/b^d.
- If a < b^d then the ratio is < 1 and the sum is a constant; hence the total work is \Theta (n^d).
- If a = b^d then the ratio is 1 and the sum is \Theta (\log _b n); hence the total work is \Theta (n^d \log n).
- If a > b^d then the ratio is > 1 and the sum is proportional to its final term, (a/b^d)^{\log _b n}. In that case the total work is \Theta \left ( n^d \cdot \left (\frac {a}{b^d}\right )^{\log _b n} \right ) = \Theta \left ( n^d \cdot \frac {a^{\log _b n}}{(b^{\log _b n})^d}\right ) = \Theta (a^{\log _b n}) = \Theta (n^{\log _b a}).