Skip to content
Official PYQ · 2024

GATE CS 2024 Set 1 Q32 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

Consider the following recurrence relation:

T(n)={nT(n)+n for n≥1,1 for n=1T(n)=\left\{\begin{array}{c}\sqrt{n} T(\sqrt{n})+n \text{ for } n \geq 1, \\ 1 \quad \text{ for } n=1\end{array}\right.

Which one of the following options is CORRECT?

 

Choose one option
View worked solution

Answer: A

To solve the recurrence relation T(n)=nT(n)+nT(n) = \sqrt{n} T(\sqrt{n}) + n, we can simplify it by dividing both sides by nn:

T(n)n=nT(n)n+1=T(n)n+1\frac{T(n)}{n} = \frac{\sqrt{n} T(\sqrt{n})}{n} + 1 = \frac{T(\sqrt{n})}{\sqrt{n}} + 1

Let S(n)=T(n)nS(n) = \frac{T(n)}{n}. Substituting this into the equation gives:

S(n)=S(n)+1S(n) = S(\sqrt{n}) + 1

Now, we apply a change of variables. Let n=2mn = 2^m, which means n=2m/2\sqrt{n} = 2^{m/2}. Substituting these into the recurrence:

S(2m)=S(2m/2)+1S(2^m) = S(2^{m/2}) + 1

Letting R(m)=S(2m)R(m) = S(2^m), we get the standard recurrence:

R(m)=R(m/2)+1R(m) = R(m/2) + 1

Using the Master Theorem, the solution to this recurrence is:

R(m)=Θ(log⁡m)R(m) = \Theta(\log m)

Substituting back m=log⁡nm = \log n and S(n)=R(m)S(n) = R(m):

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

Finally, since T(n)=n⋅S(n)T(n) = n \cdot S(n):

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

Thus, the correct option is A.

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

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