The Gateway to Computer Science Excellence

0 votes

Finding the running time of the following algorithm.

$Procedure$ $A(n)$

$\textrm{ if (n}<=\textrm{2) then return 1 ;}$

$else$

$Return(A(\left \lceil \sqrt{n} \right \rceil))$

$Procedure$ $A(n)$

$\textrm{ if (n}<=\textrm{2) then return 1 ;}$

$else$

$Return(A(\left \lceil \sqrt{n} \right \rceil))$

+2 votes

Best answer

Please refer this https://gateoverflow.in/1243/gate2007-45

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

Let $n = 2^{m} $

$T(2^{m}) = T(\sqrt{2^{m}}) +1;$

$T(2^{m}) = T(2^{m/2}) +1;$

Now let $T(2^{m}) = S(m)$

So $S(m) = S(\frac{m}{2} ) +1$

It is binary search recurrence relation

so $S(m) = O(log m)= O(log log n)$ ($\because n = 2^{m}$)

since $T(n) = T(2^{m}) = S(m)$

T(n) is $O(log log n)$

52,345 questions

60,506 answers

201,910 comments

95,342 users