The GATE Grind

GATE 2017 CS (CS2) – Question 40

Algorithms · Asymptotic Analysis and Time/Space Complexity · 2 marks · Multiple choice

$T(n)=2T(\sqrt n)+1$ for n>2, and T(n)=2 for 0<n≤2. Find its asymptotic order.

  1. $\Theta(\log\log n)$
  2. $\Theta(\log n)$
  3. $\Theta(\sqrt n)$
  4. $\Theta(n)$

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) $\Theta(\log n)$

Explanation

Set m=log₂n and S(m)=T(2ᵐ). Then S(m)=2S(m/2)+1 with constant-size base case, so S(m)=Θ(m) by the master theorem. Substitution back gives T(n)=Θ(log n), B. Equivalently the recursion tree has Θ(log n) leaves.

More Asymptotic Analysis and Time/Space Complexity questions

All Asymptotic Analysis and Time/Space Complexity questions →