Skip to content
Official PYQ · 2003

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

Explain with AI

Consider the following recurrence relation

T(1)=1T(1)=1

T(n+1)=T(n)+⌊n+1⌋T(n+1) = T(n)+\lfloor \sqrt{n+1} \rfloor for all n≥1n \geq 1

The value of T(m2)T(m^2) for m≥1m \geq 1 is

Choose one option
View worked solution

Answer: B

We can solve this recurrence relation by substituting small values of mm to eliminate options, or by analytical summation.

Method 1: Substitution (Fastest)

Using the recurrence relation T(n+1)=T(n)+⌊n+1⌋T(n+1) = T(n) + \lfloor \sqrt{n+1} \rfloor with T(1)=1T(1) = 1:

  • T(2)=T(1)+⌊2⌋=1+1=2T(2) = T(1) + \lfloor \sqrt{2} \rfloor = 1 + 1 = 2
  • T(3)=T(2)+⌊3⌋=2+1=3T(3) = T(2) + \lfloor \sqrt{3} \rfloor = 2 + 1 = 3
  • T(4)=T(3)+⌊4⌋=3+2=5T(4) = T(3) + \lfloor \sqrt{4} \rfloor = 3 + 2 = 5
  • T(9)=16T(9) = 16 and T(16)=38T(16) = 38

Now, let us evaluate the options for m=4m = 4 where T(m2)=T(16)=38T(m^2) = T(16) = 38:

  • Option A: 46(21(4)−39)+4=34≠38\frac{4}{6}(21(4) - 39) + 4 = 34 \neq 38
  • Option B: 46(4(16)−3(4)+5)=23(57)=38\frac{4}{6}(4(16) - 3(4) + 5) = \frac{2}{3}(57) = 38 (Correct)

Method 2: Analytical Derivation

Expanding the recurrence gives:

T(m2)=1+∑j=2m2⌊j⌋T(m^2) = 1 + \sum_{j=2}^{m^2} \lfloor \sqrt{j} \rfloor

For any integer kk, the value of ⌊j⌋=k\lfloor \sqrt{j} \rfloor = k for j∈[k2,(k+1)2−1]j \in [k^2, (k+1)^2 - 1]. The number of such terms is (k+1)2−k2=2k+1(k+1)^2 - k^2 = 2k + 1. Summing over all intervals from k=1k = 1 to m−1m-1, and adding the final term for j=m2j = m^2 (which is mm):

T(m2)=1−1+∑k=1m−1k(2k+1)+m=m+∑k=1m−1(2k2+k)T(m^2) = 1 - 1 + \sum_{k=1}^{m-1} k(2k+1) + m = m + \sum_{k=1}^{m-1} (2k^2 + k)T(m2)=m+2(m−1)m(2m−1)6+(m−1)m2=m(4m2−3m+5)6T(m^2) = m + 2\frac{(m-1)m(2m-1)}{6} + \frac{(m-1)m}{2} = \frac{m(4m^2 - 3m + 5)}{6}

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

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