Sub topic 12
Gaps and Non-Examples: When the Master Theorem Does Not Apply
This chapter assumes you know the three master theorem cases, the extended case 2, and how to build a recursion tree. Here we look at recurrences where the theorem gives no answer, so that you can spot them early and pick a different tool.
The theorem's preconditions
The master theorem covers T(n) = aT(n/b) + f(n) only when all of these hold:
- a ≥ 1 is a constant, so the number of subproblems does not grow with n.
- b > 1 is a constant, and every subproblem has the same size n/b.
- f(n) is asymptotically positive.
- f(n) falls into one of the cases. In case 3 it must also pass the regularity condition.
A recurrence that breaks any one of these is outside the theorem. Many recurrences that look like divide and conquer still break one.
The gap between cases
Cases 1 and 3 need f(n) to differ from n^(logb a) by a polynomial factor n^ε. If f(n) differs by less than that, such as a log factor, but is not exactly Θ(n^(logb a) log^k n) with k ≥ 0, the recurrence falls into a gap.
The standard example is T(n) = 2T(n/2) + n / log n. Here n^(log_2 2) = n, and f(n) is smaller than n by only a log factor. That is not polynomially smaller, so case 1 fails. The extended case 2 would need k = −1, and it only allows k ≥ 0.
A recursion tree gives the answer. Level j has 2^j nodes of size n/2^j, so it does a total of n / (log n − j) work. Summing over the levels gives n(1/log n + ... + 1/1), which is n times a harmonic number. So T(n) = Θ(n log log n).
Regularity failure
Case 3 also needs a·f(n/b) ≤ c·f(n) for some constant c < 1 and all large n. Polynomials always pass this check. Oscillating functions can fail it. Take T(n) = T(n/2) + n(2 − cos n). Here f(n) is Θ(n), which is polynomially larger than n^0 = 1. But at values of n where cos n is close to 1 and cos(n/2) is close to −1, f(n/2) can be about 3/2 times f(n). No constant c < 1 works, so case 3 does not apply even though f(n) looks large enough.
Recurrences of the wrong shape
| Recurrence | Why it fails | What to use instead |
|---|---|---|
| T(n) = T(n−1) + n | Subtracts from n instead of dividing it | Unrolling: Θ(n²) |
| T(n) = T(n/3) + T(2n/3) + n | The subproblems have unequal sizes | Akra-Bazzi or a recursion tree: Θ(n log n) |
| T(n) = 2ⁿT(n/2) + n | a grows with n | Unrolling or a recursion tree |
| T(n) = 0.5T(n/2) + n | a < 1 | Direct analysis |
| T(n) = T(n−1) + T(n−2) | A linear recurrence, not divide and conquer | Characteristic equation |
| T(n) = 2T(√n) + log n | Takes a square root instead of dividing | Substitute m = log n: Θ(log n log log n) |
Exercise
Can the master theorem solve T(n) = 4T(n/2) + n² / log n? If not, what is the solution?
Show answer
No. The watershed function is n², and f(n) is smaller than it by only a log factor, so the recurrence falls in the gap between case 1 and case 2. In a recursion tree, level j does n² / (log n − j) work. Summing over the levels gives n² times a harmonic number, so T(n) = Θ(n² log log n).
Exercise
Why does T(n) = T(n/4) + T(3n/4) + n fall outside the master theorem, and what is its solution?
Show answer
The two subproblems have different sizes, so the recurrence cannot be written as aT(n/b) + f(n). Every full level of the recursion tree does n work, and the depth is between log4 n and log{4/3} n. So T(n) = Θ(n log n), which Akra-Bazzi confirms.