4

Find the asymptotic tight bound in

$$ T(n) = 4T\left(\frac{n}{2}\right) + n^{2}\log n. $$

where $ \log n= \log _{2}n $ and $T(1) = 1$.

I should solve this using all three common methods: iteration, master theorem and substitution.

It is highly likely that this kind of recurrence equation will be in my test in two days. Thank you very much in advance!

SuzieQ
  • 45

2 Answers2

4

You're likely to get a comment about asking multiple questions as one big one, but to get you started, I'll do an iterative expansion.

Let $n=2^k$, since strictly speaking those are the only values for which your recurrence makes sense. Then your recurrence takes the form $$ T(2^k) = 2^2T(2^{k-1})+2^{2k}k $$ Now let's iterate $$\begin{align} T(2^k) &= 2^2[T(2^{k-1})]+2^{2k}k \\ &= 2^2[2^2T(2^{k-2})+2^{2(k-1)}(k-1)]+2^{2k}k\\ &\qquad= 2^4T(2^{k-2})+2^{2k}(k-1)+2^{2k}k\\ &= 2^4[2^2T(2^{k-3})+2^{2(k-2)}(k-2)]+2^{2k}(k-1)+2^{2k}k\\ &\qquad= 2^6T(2^{k-3})+2^{2k}(k-2)+2^{2k}(k-1)+2^{2k}k \end{align}$$ and the general pattern appears to be $$\begin{align} T(2^k) &= 2^{2j}T(2^{k-j})+2^{2k}(k-j+1)+2^{2k}(k-k+2)+\cdots+2^{2k}k\\ &= 2^{2j}T(2^{k-j})+2^{2k}((k-j+1)+(k-j+2)+\cdots k) \end{align}$$ assuming we've correctly guessed the pattern, we let $j=k$ and obtain $$ T(2^k)= 2^{2k}T(2^0)+2^{2k}(1+2+3+\cdots k)=(2^k)^2+(2^k)^2\frac{k(k+1)}{2} $$ Finally, recall that we set $n=2^k$ so $k=\lg n$ so we have the solution $$ T(n) =n^2+n^2\frac{\lg n(\lg n+1)}{2}=\Theta(n^2\lg^2n) $$ Now all you have to do is complete the remaining two parts. (grins)

Rick Decker
  • 8,718
  • Thank you very much! It was very wise to ask here because my solution was wrong. (See the latest comment. :) ) – SuzieQ Dec 10 '13 at 20:01
  • Hi Rick, one more question. Why did you let j=k? I know otherwise it will be hard to get any result but has it other reason too? I just don't see it. – SuzieQ Dec 11 '13 at 16:02
  • I tried the substitution which is the method which I have most problems with. I used the same n=2^{k} and T(2^k)=S(m) and got S(m) = 4S(m-1) + m^(2)*log(m) and I got lost again. Could you please give me some hints about the other method too. I know I am lame but I really tried. Probably should find better study materials too. Could you recommend me some literature on this subject please? It seems that you know this part of math very well. – SuzieQ Dec 11 '13 at 21:53
2

We can compute exact formulas for your recurrence and not just at powers of two. Suppose we first solve the recurrence $$T(n) = 4 T(\lfloor n/2\rfloor) + n^2 (1+\lfloor \log_2 n\rfloor)$$ with $T(0)=0.$

Then let $$n= \sum_{k=0}^{\lfloor \log_2 n\rfloor} d_k 2^k$$ be the binary representation of $n$ and unroll the recursion to get the following exact formula for $T(n):$ $$T(n) = \sum_{j=0}^{\lfloor \log_2 n\rfloor} 4^j (1+\lfloor \log_2 n\rfloor -j) \left(\sum_{k=j}^{\lfloor \log_2 n\rfloor} d_k 2^{k-j} \right)^2 \\= \sum_{j=0}^{\lfloor \log_2 n\rfloor} (1+\lfloor \log_2 n\rfloor -j) \left(\sum_{k=j}^{\lfloor \log_2 n\rfloor} d_k 2^k \right)^2.$$

Now to get an upper bound on this consider a string of one digits, which gives $$T(n)\le \sum_{j=0}^{\lfloor \log_2 n\rfloor} (1+\lfloor \log_2 n\rfloor -j) \left(\sum_{k=j}^{\lfloor \log_2 n\rfloor} 2^k \right)^2 = \sum_{j=0}^{\lfloor \log_2 n\rfloor} (1+\lfloor \log_2 n\rfloor -j) (2^{1+\lfloor \log_2 n\rfloor}-2^j)^2 \\ = \sum_{j=1}^{1+\lfloor \log_2 n\rfloor} j (2^{1+\lfloor \log_2 n\rfloor}-2^{1+\lfloor \log_2 n\rfloor-j})^2 =2^{2(1+\lfloor \log_2 n\rfloor)} \sum_{j=1}^{1+\lfloor \log_2 n\rfloor} j \times (1-2^{-j})^2.$$ The dominant term in the sum is $j$ which contributes $\sum_{j=1}^{1+\lfloor \log_2 n\rfloor} j$ to give $$\frac{1}{2} 2^{2(1+\lfloor \log_2 n\rfloor)} (1+\lfloor \log_2 n\rfloor)(2+\lfloor \log_2 n\rfloor).$$ For a lower bound consider a one followed by zeros to obtain $$T(n)\ge \sum_{j=0}^{\lfloor \log_2 n\rfloor} (1+\lfloor \log_2 n\rfloor -j) 2^{2\lfloor \log_2 n\rfloor} = 2^{2\lfloor \log_2 n\rfloor}\sum_{j=1}^{1+\lfloor \log_2 n\rfloor} j.$$ Simplifying the sum term we get $$\frac{1}{2} 2^{2\lfloor \log_2 n\rfloor} (1+\lfloor \log_2 n\rfloor)(2+\lfloor \log_2 n\rfloor)$$ which is exact this time compared to the upper bound which was asymptotic.

The conclusion is that by taking the two bounds together we obtain $$T(n)\in\Theta\left(2^{2\lfloor \log_2 n\rfloor} (1+\lfloor \log_2 n\rfloor)(2+\lfloor \log_2 n\rfloor)\right) = \Theta\left(n^2 \times \log^2 n\right).$$

A variety of Master Theorem computations can be found at this MSE link. In fact there is another very similar solution to this problem at this MSE link II.

Marko Riedel
  • 61,317
  • Thank you very much! It was very wise to ask here because my solution was wrong. I got only $n\log^{2}n$. Now I know where I failed. I am not such a mathematical star and this really helped me a lot. Maybe I will now pass my exam thanks to you and Rick! – SuzieQ Dec 10 '13 at 20:00
  • Thank you very much. BTW It never hurts to upvote an answer you found useful, like those two above. – Marko Riedel Dec 10 '13 at 20:15
  • I tried but it said that I have to have at least 15 reputation. :( – SuzieQ Dec 10 '13 at 20:39
  • No problem. Good luck. – Marko Riedel Dec 10 '13 at 20:40
  • Maybe when I reach it I will come back. I cannot promise that BUT I know that I will try to remember. ;) Thanks. – SuzieQ Dec 10 '13 at 21:09
  • @SuzieQ. With 1 or more reputation, you can "accept" an answer, by clicking on the checkmark to the left of an answer. Sad to say you can only accept one answer, and you have, IMO, two good ones, from responders with nearly identical reputations. – Rick Decker Dec 11 '13 at 00:01
  • @RickDecker: I did as I promised. I really appreciate everybody here and I am glad I found this place. Because even if my question was too general with no ( at least partial) solution you (and Marko) have helped me and I got no ugly comments even if this time I would have to admit that I have earned them. THUMBS UP – SuzieQ Dec 11 '13 at 23:05