Master Theorem Proof
For $f(n) = n^x(\log n)^k$ — Step by Step
Goal: Solve the recurrence $T(n) = aT(n/b) + f(n)$ where
$f(n) = n^x(\log n)^k$ where $x \geq 0$ and $k \geq 0$. In most textbooks, $k=0$, there are no logarithmic terms (i.e., $f(n) = n^x$).
Assume $n = b^h$, where $h = \log_b n$ is the height of the recursion tree.
Base case: $T(1) = \Theta(1)$.
Step 1: Expand the recurrence once by substituting for $T(n/b)$:
$$T(n) = a \left[ aT(n/b^2) + f(n/b) \right] + f(n)$$
Step 2: Distribute $a$ to get the expansion after 2 levels:
$$T(n) = a^2 T(n/b^2) + a f(n/b) + f(n)$$
Step 3: Expand again (level 3) to see the emerging summation pattern:
$$T(n) = a^3 T(n/b^3) + a^2 f(n/b^2) + a f(n/b) + f(n)$$
Step 4: After $h$ levels of recursion, the general form is:
$$T(n) = a^h T(n/b^h) + \sum_{i=0}^{h-1} a^i f(n/b^i)$$
Step 5: Solve for the leaf term using $n = b^h \implies a^h = a^{\log_b n} = n^{\log_b a}$:
$$a^h T(1) = \Theta(n^{\alpha}) \text{ where } \class{definition}{\alpha = \log_b a}$$
Define $\alpha = \log_b a$.
This is the critical exponent that determines which term dominates.
Step 6: Now expand the summation term using $f(n) = n^x(\log
n)^k$:
$$\sum_{i=0}^{h-1} a^i \left(\frac{n}{b^i}\right)^x \left(\log \frac{n}{b^i}\right)^k$$
Step 7: Factor out $n^x$ and regroup terms in the summation:
$$n^x \sum_{i=0}^{h-1} \left(\frac{a}{b^x}\right)^i \left(\log \frac{n}{b^i}\right)^k$$
Step 8: Define the ratio $r = a/b^x = b^{\alpha -
x}$.
The total work is:
$$T(n) = \Theta(n^{\alpha}) + n^x \sum_{i=0}^{h-1} r^i (\log(n/b^i))^k$$
The key insight: Compare $r$ with 1
(equivalently, compare $x$ with $\alpha$).
The ratio $r > 1$ means the work grows geometrically at each level.
Case 1 Deep Dive: Re-index from the leaves up ($j = h - i$ where $j$ is distance from
leaves):
$$n^x r^h \sum_{j=1}^{h} \frac{1}{r^j} (j \log b)^k$$
Because $r > 1$, the term $(1/r)^j$ decays exponentially.
The series $\sum (1/r)^j j^k$ converges to a constant as $h \to \infty$.
The total work is dominated by the leaf work:
$n^x r^h = n^x (a/b^x)^{\log_b n} = n^{\alpha}$.
Result: $T(n) = \Theta(n^{\log_b a})$
The ratio $r = 1$ means every level does roughly the same work.
The sum becomes:
$$n^{\alpha} \sum_{i=0}^{h-1} (\log(n/b^i))^k = n^{\alpha} (\log b)^k \sum_{j=1}^{h} j^k$$
Using the power sum property $\sum_{j=1}^h j^k = \Theta(h^{k+1})$, and
$h = \log_b n$:
Result: $T(n) = \Theta(n^{\alpha} (\log n)^{k+1})$
The ratio $r < 1$ means work decays geometrically from root to leaves.
The sum is dominated by the root term ($i = 0$):
$$n^x \sum_{i=0}^{h-1} r^i (\log(n/b^i))^k = \Theta(n^x (\log n)^k)$$
Because $x > $ $\alpha$,
$n^x (\log n)^k$ dominates $n^{\alpha}$.
Result: $T(n) = \Theta(f(n)) = \Theta(n^x (\log n)^k)$
Summary of Solutions:
$$T(n) = \begin{cases}
\Theta(n^{\log_b a}) & x < \log_b a \\ \Theta(n^x \log^{k+1} n) & x=\log_b a \\ \Theta(n^x \log^k n) & x>
\log_b a
\end{cases}$$
If we set $k=0$, we get the Master Theorem for $f(n) = n^x$.
Q.E.D. Proof Complete. ∎