Show that if \(f(n) = \Theta(n^{\log_b a} \lg^k n)\), where \(k \geq 0\), then the master recurrence has solution \(T(n) = \Theta(n^{\log_b a} \lg^{k+1} n)\). For simplicity, confine your analysis to exact powers of \(b\).

Think about what happens when \(f(n)\) grows exactly like \(n^{\log_b a}\) but with logarithmic factors attached. The standard master theorem’s case 2 handles \(f(n) = \Theta(n^{\log_b a})\) (when \(k = 0\)), giving \(T(n) = \Theta(n^{\log_b a} \lg n)\). What if we multiply \(f(n)\) by \(\lg^k n\)? Intuitively, each level of the recursion tree contributes work that includes a logarithmic term, and when we sum across all \(\Theta(\lg n)\) levels, these logarithmic factors accumulate, giving us one additional logarithmic factor in the final solution.

To see a concrete example, consider the recurrence \(T(n) = 2T(n/2) + n \lg n\). Here \(a = 2\), \(b = 2\), so \(n^{\log_b a} = n\), and \(f(n) = n \lg n = \Theta(n \lg^1 n)\) (so \(k = 1\)). The recursion tree has \(\lg n\) levels. At level \(j\), there are \(2^j\) subproblems of size \(n/2^j\), each contributing \(\Theta((n/2^j) \lg(n/2^j))\) work. The total work per level is \(\Theta(n \lg(n/2^j))\), and summing across all levels gives us \(\Theta(n \lg^2 n)\) (one additional logarithmic factor, as predicted by \(k + 1 = 2\)).

This scenario falls between case 1 and case 3 of the master theorem. The function \(f(n)\) is asymptotically equal to \(n^{\log_b a}\) but multiplied by a logarithmic factor \(\lg^k n\). Let’s prove the general result.

From Lemma 4.2 in the text, for exact powers of \(b\), we have:

\[T(n) = \Theta(n^{\log_b a}) + \sum_{j=0}^{\log_b n - 1} a^j f(n/b^j)\]

Since \(f(n) = \Theta(n^{\log_b a} \lg^k n)\), there exist positive constants \(c_1\) and \(c_2\) such that for sufficiently large \(n\):

\[c_1 n^{\log_b a} \lg^k n \leq f(n) \leq c_2 n^{\log_b a} \lg^k n\]

Therefore:

\[\begin{align*} f(n/b^j) &= \Theta\left(\left(\frac{n}{b^j}\right)^{\log_b a} \lg^k\left(\frac{n}{b^j}\right)\right) \\ &= \Theta\left(\frac{n^{\log_b a}}{(b^j)^{\log_b a}} \lg^k\left(\frac{n}{b^j}\right)\right) \\ &= \Theta\left(\frac{n^{\log_b a}}{a^j} \lg^k\left(\frac{n}{b^j}\right)\right) \end{align*}\]

This uses the fact that \(b^{\log_b a} = a\).

Now we need to evaluate the summation:

\[\begin{align*} g(n) &= \sum_{j=0}^{\log_b n - 1} a^j f(n/b^j) \\ &= \sum_{j=0}^{\log_b n - 1} a^j \cdot \Theta\left(\frac{n^{\log_b a}}{a^j} \lg^k\left(\frac{n}{b^j}\right)\right) \\ &= \Theta\left(n^{\log_b a} \sum_{j=0}^{\log_b n - 1} \lg^k\left(\frac{n}{b^j}\right)\right) \end{align*}\]

Using the logarithm property \(\lg(n/b^j) = \lg n - \lg b^j = \lg n - j \lg b\), we have:

\[g(n) = \Theta\left(n^{\log_b a} \sum_{j=0}^{\log_b n - 1} (\lg n - j \lg b)^k\right)\]

Let \(m = \log_b n\), so \(\lg n = m \lg b\). Then:

\[\begin{align*} g(n) &= \Theta\left(n^{\log_b a} \sum_{j=0}^{m - 1} (m \lg b - j \lg b)^k\right) \\ &= \Theta\left(n^{\log_b a} (\lg b)^k \sum_{j=0}^{m - 1} (m - j)^k\right) \end{align*}\]

Substituting \(i = m - j\):

\[g(n) = \Theta\left(n^{\log_b a} (\lg b)^k \sum_{i=1}^{m} i^k\right)\]

For the sum \(\sum_{i=1}^{m} i^k\), we know from calculus and Faulhaber’s formula that:

\[\sum_{i=1}^{m} i^k = \Theta(m^{k+1})\]

This is because the sum is asymptotically equivalent to \(\int_1^m x^k \, dx = \frac{m^{k+1}}{k+1} - \frac{1}{k+1} = \Theta(m^{k+1})\).

Therefore:

\[\begin{align*} g(n) &= \Theta\left(n^{\log_b a} (\lg b)^k m^{k+1}\right) \\ &= \Theta\left(n^{\log_b a} (\lg b)^k (\log_b n)^{k+1}\right) \end{align*}\]

Since \(\log_b n = \frac{\lg n}{\lg b}\), we have:

\[(\log_b n)^{k+1} = \frac{(\lg n)^{k+1}}{(\lg b)^{k+1}}\]

Thus:

\[\begin{align*} g(n) &= \Theta\left(n^{\log_b a} (\lg b)^k \cdot \frac{(\lg n)^{k+1}}{(\lg b)^{k+1}}\right) \\ &= \Theta\left(n^{\log_b a} \frac{(\lg n)^{k+1}}{\lg b}\right) \\ &= \Theta(n^{\log_b a} \lg^{k+1} n) \end{align*}\]

From Lemma 4.2:

\[T(n) = \Theta(n^{\log_b a}) + g(n) = \Theta(n^{\log_b a}) + \Theta(n^{\log_b a} \lg^{k+1} n)\]

Since the second term dominates (for \(n \geq 2\), \(\lg^{k+1} n \geq 1\)), we have:

\[T(n) = \Theta(n^{\log_b a} \lg^{k+1} n)\]