Skip to content
Official PYQ · 2023

GATE CS 2023 Q44 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

Consider functions Function_1\textsf{Function\_1} and Function_2\textsf{Function\_2} expressed in pseudocode as follows:

Function_1
    while n>1 do
        for i=1 to n do
            x = x + 1;
        end for
        n = ⌊n/2⌋;
    end while
Function_2
   for i = 1 to 100 * n do
       x = x + 1;
   end for

 

Let f1(n)f_{1}(n) and f2(n)f_{2}(n) denote the number of times the statement “x = x + 1”\textsf{“x = x + 1”} is executed in Function_1\textsf{Function\_1} and Function_2,\textsf{Function\_2}, respectively.

Which of the following statements is/are TRUE?\text{TRUE}?

Select all correct options
View worked solution

Answer: A;D

To determine the correct options, let us analyze the execution counts f1(n)f_1(n) and f2(n)f_2(n) for the statement x = x + 1 in both functions.

Analysis of Function_1\textsf{Function\_1}:

In each iteration of the outer while loop, the value of nn is halved. The inner for loop runs nn times. Therefore, the total number of executions f1(n)f_1(n) is given by the sum of a geometric progression: f1(n)=n+⌊n/2⌋+⌊n/4⌋+⋯+1f_1(n) = n + \lfloor n/2 \rfloor + \lfloor n/4 \rfloor + \dots + 1 Using the properties of geometric series, we have: n≤f1(n)<n∑i=0∞12i=2nn \le f_1(n) < n \sum_{i=0}^{\infty} \frac{1}{2^i} = 2n Thus, f1(n)∈Θ(n)f_1(n) \in \Theta(n).

Analysis of Function_2\textsf{Function\_2}:

The loop runs exactly 100n100n times. Thus, the statement is executed: f2(n)=100nf_2(n) = 100n This clearly means f2(n)∈Θ(n)f_2(n) \in \Theta(n).

Evaluating the Options:

  • Option A: Since both f1(n)f_1(n) and f2(n)f_2(n) are in Θ(n)\Theta(n), they are asymptotically equivalent. Hence, f1(n)∈Θ(f2(n))f_1(n) \in \Theta(f_2(n)) is TRUE.
  • Option B: f1(n)∈o(f2(n))f_1(n) \in o(f_2(n)) is false because f1(n)f_1(n) does not grow strictly slower than f2(n)f_2(n) (their ratio is a non-zero constant ≈1/50\approx 1/50).
  • Option C: f1(n)∈ω(f2(n))f_1(n) \in \omega(f_2(n)) is false because f1(n)f_1(n) does not grow strictly faster than f2(n)f_2(n).
  • Option D: Since f1(n)∈Θ(n)f_1(n) \in \Theta(n), it also satisfies the upper bound f1(n)∈O(n)f_1(n) \in O(n), which is TRUE.

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

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