1

$$ T(n)=\sqrt{n}T(\sqrt{n})+n $$

$$T(1)=T(2)=1$$

the answer is given as $$ \Theta(n\log \log n) $$ I tried to draw recursion tree, it got all crazy

I tried using substitution method instead $$\sqrt{n}=2^{m}$$ $$T(2^{m})=2^{m/2}T(2^{m})+2^{m}$$ $$S(m)=\frac{m}{2}S(m)+m$$ $$\frac{S(m)}{m}=\frac{1}{2}S(m)+1$$ am I right?

David Richerby
  • 82,470
  • 26
  • 145
  • 239

1 Answers1

1

In the second line of your solution, you shouldn't have two terms $T(2^m)$. Here's a correct derivation: $$\begin{align} T(n) &= \sqrt{n}\ T(\sqrt{n}) + n & \text{so, dividing by $n$ we get}\\ \frac{T(n)}{n} &= \frac{T(\sqrt{n})}{\sqrt{n}} + 1 &\text{and letting $n = 2^m$ we have}\\ \frac{T(2^m)}{2^m} &= \frac{T(2^{m/2})}{2^{m/2}} + 1 \end{align}$$ Now let $$\begin{align} S(m) &= \frac{T(2^m)}{2^m} & \text{so our original recurrence becomes}\\ S(m) &= S(m/2)+1 \end{align}$$ which is a well-known recurrence with solution $$ S(m)=\Theta(\lg m) $$ Returning to $T()$ we then have, with $n=2^m$ (and $m=\lg n$), $$ \frac{T(n)}{n} = \Theta(\lg\,\lg n) $$ So $T(n) =\Theta(n\,\lg\,\lg n)$.

This has been asked before: Solving a recurrence relation with √n as parameter, though this particular substitution solution wasn't included among the answers

Rick Decker
  • 15,016
  • 5
  • 43
  • 54