Skip to content
Official PYQ · 2016

GATE CS 2016 Set 2 Q39 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

The given diagram shows the flowchart for a recursive function A(n)A(n). Assume that all statements, except for the recursive calls, have O(1)O(1) time complexity. If the worst case time complexity of this function is O(nα)O(n^{\alpha}), then the least possible value (accurate up to two decimal positions) of α\alpha is ________.

Flow chart for Recursive Function A(n)A(n).

View worked solution

Answer: 2.32 : 2.33

In the worst-case scenario, the recursive function A(n)A(n) follows the path in the flowchart that maximizes the number of recursive calls.

From the flowchart, when nn is odd, the function branches to make 55 recursive calls of size approximately n/2n/2 (specifically, ⌊n/2⌋\lfloor n/2 \rfloor and ⌈n/2⌉\lceil n/2 \rceil). When nn is even, it makes fewer recursive calls. Therefore, the worst-case recurrence relation is:

T(n)=5T(n2)+Θ(1)T(n) = 5T\left(\frac{n}{2}\right) + \Theta(1)

Applying the Master Theorem for recurrences of the form T(n)=aT(n/b)+Θ(nk)T(n) = aT(n/b) + \Theta(n^k):

  • a=5a = 5
  • b=2b = 2
  • k=0k = 0

Since log⁡ba=log⁡25≈2.3219>k\log_b a = \log_2 5 \approx 2.3219 > k, the time complexity is:

T(n)=Θ(nlog⁡25)≈Θ(n2.32)T(n) = \Theta\left(n^{\log_2 5}\right) \approx \Theta\left(n^{2.32}\right)

Comparing this with O(nα)O(n^\alpha), the least possible value of α\alpha is log⁡25≈2.32\log_2 5 \approx 2.32.

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

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