1

T(n) = 2T(√n) + n.


I tried putting n=2^m

T(2^m) = 2T(2^(m/2)) + 2^m.

If I subsitute T(2^m) = S(m) then,

S(m) = 2S(m/2) + 2^m.

This is same as (1*2^m) + (2*2^(m/2)) + (4*2^(m/4)) + ...

Now I am stuck in this summation as it's not a GP.

Can someone please help?

Raphael
  • 72,336
  • 29
  • 179
  • 389
Zephyr
  • 993
  • 3
  • 16
  • 32

1 Answers1

2

The solution is $T(n) = \Theta(n)$. It is easy to see that $T(n) = \Omega(n)$ (indeed, $T(n) \geq n$), and you can prove $T(n) = O(n)$ by induction: choose some constant $C>0$. Suppose that you have shown that all small enough $n$ satisfy $T(n) \leq Cn$. Then for larger $n$, $$ T(n) \leq 2T(\sqrt{n}) + n \leq 2C\sqrt{n} + n = \left(\frac{2C}{\sqrt{n}} + 1\right)n. $$ This is at most $Cn$ if $2C/\sqrt{n}+1 \leq C$, and in particular if $n \geq 16$ and $C \geq 1$. Therefore if we define $C = \max(1,T(1)/1,\ldots,T(15)/15)$ then the argument above shows that $T(n) \leq Cn$.

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
  • Can we use masters theorem here? The function f(n) = 2^m doesn't seem to be in the form required for applying masters theorem – Zephyr Dec 15 '17 at 13:13
  • Verifying the conditions of the master theorem is something you can do on your own. – Yuval Filmus Dec 15 '17 at 13:15