$T(n)=\sqrt{2T(n-1)}$ what will be the time complexity if $T(n)$ is given as this? I tried substitution but no result was reached.
2 Answers
The answer depends on the initial value. For example, if $T(0) = 2$ then you can prove by induction that $T(n) = 2$ for all $n$. More generally, let $S(n) = T(n)/2$. Then $$ S(n) = \frac{T(n)}{2} = \frac{\sqrt{2T(n-1)}}{2} = \sqrt{\frac{T(n-1)}{2}} = \sqrt{S(n-1)}. $$ Simple induction now shows that $S(n) = \sqrt[2^n]{S(0)}$, and so $$ T(n) = 2 \sqrt[2^n]{\frac{T(0)}{2}}. $$ In particular, this shows that $T(n) \to 2$.
We can estimate the speed of convergence using the estimate $$ \sqrt[2^n]{x} = \exp \frac{\log x}{2^n} = 1 + O\left(\frac{\log x}{2^n}\right). $$ This shows that $$ T(n) = 2 + O(2^{-n}). $$
- 280,205
- 27
- 317
- 514
With substitution, we will get $T(n) = \sqrt{2\sqrt{2\sqrt{\cdots\sqrt{2}}}}$ with length $n$. Now, suppose $n$ goes to $\infty $, we will have $A = \sqrt{2A}$. Therefore, $A^2-2A = 0$ and $A = 2$. Hence, $T(n)$ would be constant as $T(n)$ is increasing. And we can write $T(n) =\Theta(1)$.
- 3,612
- 1
- 15
- 23