6

what is the complexity of below relation

$ T(n) = 2*T(\sqrt n) + \log n$

and $T(2) = 1$

Is it $\Theta (\log n * \log \log n)$ ?

Kaveh
  • 22,231
  • 4
  • 51
  • 111
  • Welcome! Why are you interested in this recurrence? What have you tried? Have you checked our reference question? – Raphael Aug 29 '12 at 12:19
  • @Raphael : I solved the recurrence but I was skeptical about the result. So posted the question here. I got this came across this eq while solving some recurrences. I got answer theta(log(n) * loglog(n)). – panthera onca Aug 29 '12 at 13:00
  • 1
    In that case, please edit your attempt into the question! Why ask people to do all the calculations if all you want is somebody to check yours? (SE does not work too well for questions of this type, by the way.) – Raphael Aug 29 '12 at 13:03
  • @Raphael I posted this question in math with the answer but I didn't get any answers so I posted it here without answer. I thought nobody will answer my question if it's already solved. I even edited this in math and I got the answer afterwards. Next time will keep this in mind while posting :) – panthera onca Aug 29 '12 at 13:08
  • I did not mean to include the final result only, but also how you got there. That will allow people willing to help you to spot mistakes more easily (rather than doing the whole thing). "Check-my-proof" questions are unlikelier than others to receive an answer (esp. if they are not obviously wrong), but including your own attempt is obligatory. Also, please link crossposted questions back and forth so there is no duplicate effort. – Raphael Aug 29 '12 at 15:02
  • Check your answer here – mrk Aug 29 '12 at 15:38
  • Hint: Consider $$g(n) = \frac{T(n)}{\log_2 n}$$ – Aryabhata Aug 29 '12 at 16:10
  • 2
    Do you really want the complexity of the recurrence, or do you just want its solution? – JeffE Aug 30 '12 at 11:51

1 Answers1

6

Yes, the answer is $\lg n \cdot \lg \lg n$:

Reason this out by expanding the recurrence and looking for a pattern:

\begin{align*} T(n) &= 2T(\sqrt{n}) + \lg n \\ &= 2( 2T( \sqrt[4]{n} ) + \log(\sqrt{n}) ) + \lg n \\ &= 2\left( 2T(\sqrt[4]{n}) + \frac{1}{2} \lg n \right) + \lg n \\ &= 4T( \sqrt[4]{n} ) + 2 \lg n \\ &= 4( 2T( \sqrt[8]{n} ) + \lg\sqrt[8]{n} ) + 2 \lg n \\ &= 8T( \sqrt[8]{n} ) + 3 \lg n \\ \end{align*} So as we continue expanding this and taking the square root of $n$, we will eventually bottom out where $n < 2$. To figure out how many times we can take the square root of $n$, consider $n = 2^{\lg n}$, and on each recursive call, $n$ will have its square root taken. Ending when $n < 2$ gives us: \begin{align*} 2^{\frac{\lg n}{2^k}} &= 2 \\ \frac{\lg n}{2^k} &= 1 \\ \lg n &= 2^k \\ k &= \lg \lg n \end{align*}

Giving a solution of $\lg n \lg \lg n$.

Alternatively, this can be solved via variable substitution and the Master Theorem. Substituting $m = \lg n$: \begin{align*} T(2^m) &= 2T(2^{m/2}) + m \\ S(m) &= 2S(m/2) + m \end{align*} At this point the Master Theorem applies, with $a=2$, $b=2$, and $f(m) = m$. Since $m^{\log_b a} = m^{\lg 2} = m$, resulting in $f(m) = m = \Theta(m^{\log_b a})$. Therefore case 2 of the Master Theorem applies, and the solution is $m \lg m$. Substituting $m = \lg n$ gives us $T(n) = \lg n \lg \lg n$.

Edit: fixed a typo (needed to write this to exceed the minimum number of characters).

Ken P
  • 316
  • 1
  • 3