5

A former student of mine was TA-ing an algorithms class last quarter and asked students to solve this famous recurrence relation:

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

There are several ways to solve this recurrence relation and this question has already been asked here.

I was talking to my student about this problem and mentioned that it's quite hard to solve and is pretty dependent on the particular choices being made. As an example, I suggested this variant of a recurrence relation that was less simple to solve:

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

The TA and I tried solving this recurrence for about an hour and a half without making any progress. Here are a few things we tried:

  • My approach to solving the initial recurrence relation was to draw out a recursion tree and notice that each level of the tree contributes $n$ to the total and that there are $O(\log \log n)$ layers, so the recurrence solves to $O(n \log \log n)$. When I tried doing this here, I noticed that the work per layer was no longer constant; instead, the top layer sums to $\sqrt{n}$, the second layer to $n^{3/4}$, the third to $n^{7/8}$, etc. We got stuck working with the summation $n^{1/2} + n^{3/4} + n^{7/8} + ...$.

  • We tried using the iteration method to unroll the recurrence. With the original recurrence relation, this works out nicely; here, we got stuck at the same summation given above.

I'm completely stuck trying to figure out how to solve this recurrence relation. There's nothing riding on it per se - I don't need to solve it for any particular reason - but the fact that we arrived at it by a straightforward modification of a common algorithms problem set question makes it all the more enticing.

Any idea how to solve this recurrence?

Thanks!

2 Answers2

1

As you mention, the explicit solution (assuming appropriate initial conditions) is $$ \begin{align*} T(n) &= n^{1/2} + n^{3/4} + \cdots + n^{1-1/\log n} \\ &= n \left(\frac{1}{n^{1/2}} + \frac{1}{n^{1/4}} + \cdots + \frac{1}{n^{1/\log n}} \right). \end{align*} $$ Note that $1/n^{1/\log n} = 1/2$. Another way of writing the same formula is $$ T(n) = n\left(\frac{1}{2} + \frac{1}{2^2} + \frac{1}{2^4} + \cdots + \frac{1}{2^{2^{\log\log n-1}}} \right). $$ The infinite series $$ \sum_{k=0}^\infty \frac{1}{2^{2^k}} $$ converges to some limit $L \approx 0.81642$, and so $$ T(n) = Ln + o(n), $$ the formula holding for $n$ of the form $2^{2^k}$.

Yuval Filmus
  • 57,157
  • How is this consistent with $T(n) \gt n \implies T(n^2) \gt n^2$? – Henry Jun 18 '15 at 21:58
  • @Henry I'm assuming the initial condition $T(1) = 0$ or $T(1) = 1$ (whichever agrees with the equations). If you choose a different initial condition then you will get a different constant $L$. – Yuval Filmus Jun 18 '15 at 23:28
  • 1
    The equation might suggest something like $T(1)=T(1)+1$, which is not helpful. In fact you seem to be assuming $T(2)=0$, but I do not see why that is a reasonable restriction. For $n$ of the form $2^{2^m}$ it seems $T(n) = \left(L+\frac{T(2)}{2}\right)n+o(n)$ is more general. – Henry Jun 18 '15 at 23:32
  • @Henry The initial condition implies an additive term of the form $n^{1-1/\log n} T(2) = (T(2)/2) n$ or something very similar. So you can do the analysis under the assumption $T(2) = 0$, and then deduce the general case. – Yuval Filmus Jun 18 '15 at 23:33
0

For powers of powers of $2$, $$T(2^2)=2^1T(2^1)+2^1,\\ T(2^4)=2^2T(2^2)+2^2=2^22^1T(2^1)+2^22^1+2^2,\\ T(2^8)=2^4T(2^4)+2^4=2^42^22^1T(2^1)+2^42^22^1+2^42^2+2^4,\\ T(2^{16})=2^8T(2^8)+2^8=2^82^42^22^1T(2^1)+2^82^42^22^1+2^82^42^2+2^82^4+2^8\\ \cdots\\ T(2^{2^k})=2^{2^k-1}\left(T_2+1+\frac1{2^1}+\frac1{2^12^2}+\frac1{2^12^22^4}+\frac1{2^12^22^42^8}\cdots\right), \\ \color{green}{T(n)=\frac n2\left(T_2+S\right)+o(n)}, $$where $S\approx1.63284301804$.