-1

$T(n) = 3T(\frac{n}{3}) + n\log{n}$ How can I solve this recurrence using the iteration method? If anyone can solve it and show me how that would be really swell.

RobPratt
  • 50,938
  • Does this answer your question? https://math.stackexchange.com/questions/3085606/solving-the-recurrence-tn-3t-left-fracn3-right-n-log-2-n?noredirect=1. – Gonçalo Jun 02 '24 at 04:46

2 Answers2

5

Trying a few small cases yields \begin{align} T(3) &= 3(T(1) + \log 3) \\ T(9) &= 3T(3) + 9 \log 9 = 9(T(1) + (1 + 2) \log 3) \\ T(27) &= 3T(9) + 27 \log 27 = 27(T(1) + (1 + 2 + 3) \log 3) \end{align}

So for $n$ a power of $3$, we have $$T(n) = n\left(T(1) + \frac{1}{2}(\log_3 n)(\log_3 n + 1) (\log 3)\right).$$


As a sanity check, the master theorem implies that $T(n) = \Theta(n \log^2 n)$, which the specific solution above satisfies.

angryavian
  • 93,534
1

Here's one way to derive the dolution.

Putting $n=3^m$, $T(n) = 3T(\frac{n}{3}) + n\log{n} $ becomes $T(3^m) = 3T(3^{m-1}) + 3^m\log{3^m} = 3T(3^{m-1}) + m3^m\log{3} $.

Letting $T(3^m)=s(m)$, this is $s(m) =3s(m-1)+ m3^m\log{3} $.

Dividing by $3^m$, $\dfrac{s(m)}{3^m} =\dfrac{3s(m-1)}{3^m}+ m\log{3} =\dfrac{s(m-1)}{3^{m-1}}+ m\log{3} $..

Finally, letting $r(m)=\dfrac{s(m)}{3^m}$, this is $r(m) =r(m-1)+m\log(3) $ or $r(m)-r(m-1)=m\log(3) $.

Summing,

$\begin{array}\\ r(m)-r(0) &=\sum_{k=1}^{m} (r(k)-r(k-1))\\ &=\sum_{k=1}^{m} k\log(3)\\ &=m(m+1)\log(3)/2\\ &=cm(m+1) \qquad\text{where }c=\log(3)/2\\ \end{array} $

so $r(m)=r(0)+cm(m+1) $.

Unwinding the definitions,

$\begin{array}\\ s(m) &=3^mr(m)\\ &=3^m(r(0)+cm(m+1))\\ &=3^m(s(0)+cm(m+1))\\ &=T(3^m)\\ &\text{Setting } n=3^m, m=\log_3(n)\\ T(n) &=3^m(s(0)+cm(m+1))\\ &=n(T(1)+c\log_3(n)(\log_3(n)+1))\\ &=n(T(1)+c(\log_3^2(n)+\log_3(n)))\\ \end{array} $

This agrees with angryavian's solution.

marty cohen
  • 110,450