Skip to content
Official PYQ · 2009

GATE CS 2009 Q35 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

The running time of an algorithm is represented by the following recurrence relation:

T(n)={nn≤3T(n3)+cn otherwise T(n) = \begin{cases} n & n \leq 3 \\ T(\frac{n}{3})+cn & \text{ otherwise } \end{cases}

Which one of the following represents the time complexity of the algorithm?

Choose one option
View worked solution

Answer: A

We can solve the recurrence relation T(n)=T(n3)+cnT(n) = T\left(\frac{n}{3}\right) + cn using the Master Theorem or by expansion.

Method 1: Master Theorem
The recurrence is of the form T(n)=aT(nb)+f(n)T(n) = a T\left(\frac{n}{b}\right) + f(n), where a=1a = 1, b=3b = 3, and f(n)=cn=Θ(n)f(n) = cn = \Theta(n).

Comparing f(n)f(n) with nlog⁡ba=nlog⁡31=n0=1n^{\log_b a} = n^{\log_3 1} = n^0 = 1, we see that f(n)=Ω(n0+ϵ)f(n) = \Omega(n^{0 + \epsilon}) for ϵ=1\epsilon = 1. The regularity condition af(n/b)≤kf(n)a f(n/b) \le k f(n) holds because 1⋅cn3≤k⋅cn1 \cdot c\frac{n}{3} \le k \cdot cn for k=13<1k = \frac{1}{3} < 1. By Case 3 of the Master Theorem, T(n)=Θ(f(n))=Θ(n)T(n) = \Theta(f(n)) = \Theta(n).

Method 2: Expansion Method
Expanding the recurrence step-by-step:
T(n)=T(n3)+cn=T(n9)+cn3+cn=⋯=T(n3k)+cn∑i=0k−1(13)iT(n) = T\left(\frac{n}{3}\right) + cn = T\left(\frac{n}{9}\right) + c\frac{n}{3} + cn = \dots = T\left(\frac{n}{3^k}\right) + cn \sum_{i=0}^{k-1} \left(\frac{1}{3}\right)^i

The summation is a decreasing geometric series that converges to a constant factor 32\frac{3}{2}. Thus, T(n)=Θ(1)+32cn=Θ(n)T(n) = \Theta(1) + \frac{3}{2}cn = \Theta(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