GATE CS 2024 Set 1 — Question 42

MCQ+2 / -0.67MediumSubstitution MethodAsymptotic AnalysisAlgorithmsRecursion Tree Method

Algorithms → Asymptotic Analysis → Recursion Tree Method

Last updated

Question

Consider the following recurrence relation:T(n)={nT(n)+nfor n1,1for n=1.T(n) = \begin{cases} \sqrt{n}T(\sqrt{n}) + n & \text{for } n \ge 1, \\ 1 & \text{for } n = 1. \end{cases}Which one of the following options is CORRECT?
A.
T(n)=Θ(nloglogn)T(n) = \Theta(n \log \log n)
B.
T(n)=Θ(nlogn)T(n) = \Theta(n \log n)
C.
T(n)=Θ(n2logn)T(n) = \Theta(n^2 \log n)
D.
T(n)=Θ(n2loglogn)T(n) = \Theta(n^2 \log \log n)

Correct answer

(A) T(n) = Θ(n log log n)

Solution

The given recurrence relation is:T(n)=nT(n)+nT(n) = \sqrt{n} T(\sqrt{n}) + nTo solve this, we can use the substitution method.
Let n=2mn = 2^m, which implies m=log2nm = \log_2 n. Then n=2m/2\sqrt{n} = 2^{m/2}.
Substituting these into the recurrence:T(2m)=2m/2T(2m/2)+2mT(2^m) = 2^{m/2} T(2^{m/2}) + 2^mDivide the entire equation by 2m2^m:T(2m)2m=2m/2T(2m/2)2m+1\frac{T(2^m)}{2^m} = \frac{2^{m/2} T(2^{m/2})}{2^m} + 1T(2m)2m=T(2m/2)2m/2+1\frac{T(2^m)}{2^m} = \frac{T(2^{m/2})}{2^{m/2}} + 1Let S(m)=T(2m)2mS(m) = \frac{T(2^m)}{2^m}. The recurrence becomes:S(m)=S(m/2)+1S(m) = S(m/2) + 1This is a standard recurrence relation (similar to binary search complexity) whose solution is:S(m)=Θ(logm)S(m) = \Theta(\log m)Now, substitute back S(m)=T(n)nS(m) = \frac{T(n)}{n} and m=log2nm = \log_2 n:T(n)n=Θ(log(log2n))\frac{T(n)}{n} = \Theta(\log(\log_2 n))T(n)=nΘ(loglogn)T(n) = n \cdot \Theta(\log \log n)T(n)=Θ(nloglogn)T(n) = \Theta(n \log \log n)Thus, option (A) is correct.

More questions on Asymptotic Analysis

Practice GATE CS PYQs with adaptive difficulty

Timed practice, skill tracking, and AI explanations — free to start.

Start practicing free