edited by
17,901 views
47 votes
47 votes

The running time of the following algorithm

Procedure $A(n)$

If $n \leqslant 2$ return ($1$) else return $(A( \lceil  \sqrt{n}  \rceil))$;

is best described by

  1. $O(n)$
  2. $O(\log n)$
  3. $O(\log \log n)$
  4. $O(1)$
edited by

7 Answers

7 votes
7 votes

$Ans:C$


$T(n) = T(\sqrt n)  + c$

Assume $n=2^k$

$T(2^k)=T(2^{k/2})+c$

Assume $T(2^k)=S(k)$

$S(k)=S(k/2)+c$

Apply Master Theorem

$S(k)=\Theta(1.\log\ k)$

Now just do the reverse

$T(2^k)=\Theta(\log\ k)$

Now replace with $k=\log_{2}n$

$T(2^{\log_{2}n})=\Theta(\log(\log_{2}n))$

$T(n)=\Theta(\log(\log_{2}n))$

0 votes
0 votes
Let us replace $ n = 2^{\log{n}} $

$ A(2^{\log{n}}) $

$= A(2^{\frac{\log{n}}{2}}) + c$

$= A(2^{\frac{\log{n}}{4}}) + 2c$
…………
….……..
$= A(2^{\frac{\log{n}}{2^{k}}}) + kc$
…………
In order to get base value i.e A(2) in our equation,

$ 2^{\frac{\log{n}}{2^{k}}} = 2$

$ \frac{\log{n}}{2^{k}} = 1$

$ \log{n} = 2^{k} $

$ k = \log{\log{n}} $

substituting the value of k with our derivation,

$A(n)\ = A(2) + c\log{\log{n}} = Θ(\log{\log{n}})\  $

$[\ A(2)\ and\ c\ are\ constants,\ we\ can\ ignore\ them\ asymptotically\ ]$
Answer:

Related questions

35 votes
35 votes
2 answers
1
Kathleen asked Sep 15, 2014
11,930 views
The solution to the recurrence equation $T(2^k) = 3T(2^{k-1})+1, T(1) =1$ is$2^k$$\frac{(3^{k+1}-1)}{2}$$3^{\log_2 k}$$2^{\log_3 k}$