Skip to content
Official PYQ · 2017

GATE CS 2017 Set 2 Q30 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

Consider the recurrence function

T(n)={2T(n)+1,n>22,0<n≤2T(n) = \begin{cases} 2T(\sqrt{n})+1, & n>2 \\ 2, & 0 < n \leq 2 \end{cases}

Then T(n)T(n) in terms of Θ\Theta notation is

Choose one option
View worked solution

Answer: B

To solve the given recurrence relation:

T(n)=2T(n)+1for n>2T(n) = 2T(\sqrt{n}) + 1 \quad \text{for } n > 2

We can 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)=2T(2k/2)+1T(2^k) = 2T(2^{k/2}) + 1

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

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

We can now apply the Master Theorem for divide-and-conquer recurrences of the form S(k)=aS(k/b)+f(k)S(k) = aS(k/b) + f(k):

  • Here, a=2a = 2, b=2b = 2, and f(k)=1=Θ(k0)f(k) = 1 = \Theta(k^0).
  • Compare f(k)f(k) with klog⁡ba=klog⁡22=k1k^{\log_b a} = k^{\log_2 2} = k^1.
  • Since f(k)=O(k1−ϵ)f(k) = O(k^{1 - \epsilon}) for ϵ=1\epsilon = 1, we fall into Case 1 of the Master Theorem.

Thus, the solution for S(k)S(k) is:

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

Substituting back k=log⁡2nk = \log_2 n:

T(n)=S(log⁡2n)=Θ(log⁡n)T(n) = S(\log_2 n) = \Theta(\log n)

Therefore, the correct option is B.

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

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