Skip to content
Official PYQ · 2002

GATE CS 2002 Q2.11 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

The running time of the following algorithm

Procedure A(n)A(n)

If n⩽2n \leqslant 2 return (11) else return (A(⌈n⌉))(A( \lceil \sqrt{n} \rceil));

is best described by

Choose one option
View worked solution

Answer: C

To find the running time of the procedure A(n)A(n), we can write its recurrence relation. Let T(n)T(n) be the time complexity of the algorithm for an input size nn:

T(n)=T(⌈n⌉)+Θ(1)for n>2T(n) = T\left(\lceil \sqrt{n} \rceil\right) + \Theta(1) \quad \text{for } n > 2

To solve this recurrence, we can ignore the ceiling function for asymptotic analysis and use the change of variables method.

Let n=2kn = 2^k, which implies k=log⁡2nk = \log_2 n. Substituting this into the recurrence:

T(2k)=T((2k)1/2)+c=T(2k/2)+cT(2^k) = T\left((2^k)^{1/2}\right) + c = T(2^{k/2}) + c

Let S(k)=T(2k)S(k) = T(2^k). The recurrence relation becomes:

S(k)=S(k2)+cS(k) = S\left(\frac{k}{2}\right) + c

Applying the Master Theorem (Case 2) or by simple expansion, we get:

S(k)=Θ(log⁡k)S(k) = \Theta(\log k)

Now, substituting k=log⁡2nk = \log_2 n back into the solution:

T(n)=Θ(log⁡log⁡n)T(n) = \Theta(\log \log n)

Thus, the running time of the algorithm is best described by O(log⁡log⁡n)O(\log \log n).

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Asymptotic Worst Case Time and Space Complexity questions