Recurrence Relations – Solution to $T(n)=T (\sqrt{n}) + 1$

discrete mathematicsrecurrence-relationsrecursion

This looks like a question asked earlier, but it isn't.

$$T(n)=\begin{cases} T (\sqrt{n}) + 1 \quad & \text{ if } n>1 \\
1 & \text{ if }n=1\end{cases}$$

My professor gave this to me in class yesterday. This is where I'm stuck:

$$T(n) = T(n^{1/2})+1 = T(n^{1/4})+2 = T(n^{1/8})+3
= \dots = T(n^{1/ 2 ^k})+k$$

Now this will continue till

$$n^{1/ 2 ^k}=1$$

How do I proceed ahead? If I take log on both sides, then RHS becomes zero.
How do I solve the relation?

I don't want to use the Master theorem, I want to know where and why am I stuck.

Best Answer

We have a recurrence that is ostensibly over the integers. But if $n$ is an integer, then $\sqrt{n}$ is not necessarily an integer. One way of getting an informal answer is to imagine that we start with an integer $n$ of the form $2^{2^m}$. Then $\sqrt{n}=2^{2^{m-1}}$. (To find the square root, we divide the exponent by $2$.)

So going up from $2^{2^0}$ to $2^{2^m}$, we have incremented $T$ by $m$. If we start with $T(2)=0$, then $$T\left(2^{2^m}\right)=m.$$ If $T(2)$ has some other value $a$, then $T\left(2^{2^m}\right)=a+m$. Note that $m=\log_2\left(\log_2\left(2^{2^m}\right)\right).$ So for this value of $n$, and $T(2)=0$, we have $T(n)=\log_2(\log_2(n))$. If $T(2)=a$, just add $a$.

Remark: The above calculation can be carried out in basically the same way if we assume that $T(n)=T(\lfloor\sqrt{n}\rfloor)+1$. The conclusion is that for large $n$, $T(n)$ behaves like $\lg\lg n$. And $\lg\lg n$ grows glacially slowly.

Related Question