GateAI
Asymptotic Analysis

GATE CSE 2023 · Q54

MSQ2 marksMedium

Time

Consider functions Function_1\textbf{Function\_1} and Function_2\textbf{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 whileFunction_2 for i = 1 to 100 * n do x = x + 1; end forLet f1(n)f_1(n) and f2(n)f_2(n) denote the number of times the statement “x=x+1x = x + 1” is executed in Function_1\textbf{Function\_1} and Function_2\textbf{Function\_2}, respectively. Which of the following statements is/are TRUE?

Select all that applyOne or more correct

Pick every correct option

Solution

Step-by-step verified solution

Official answer: A) f1(n) ∈ (f2(n)); D) f1(n) ∈ O(n)

Asymptotic Analysis

Let us compute the exact number of times the statement x=x+1x = x + 1 is executed in both functions:

  1. For Function_1:

    • In the first iteration of the while loop, the inner for loop executes nn times.

    • In the second iteration, nn becomes ⌊n/2⌋\lfloor n/2 \rfloor, so the inner loop executes ⌊n/2⌋\lfloor n/2 \rfloor times.

    • This continues halving nn until n≤1n \le 1.

    • Thus, the total number of executions f1(n)f_1(n) is:

      f1(n)=n+⌊n2⌋+⌊n4⌋+⋯+2f_1(n) = n + \left\lfloor \frac{n}{2} \right\rfloor + \left\lfloor \frac{n}{4} \right\rfloor + \dots + 2
    • Using the properties of a geometric series:

      n≤f1(n)<n∑k=0∞(12)k=2nn \le f_1(n) < n \sum_{k=0}^{\infty} \left(\frac{1}{2}\right)^k = 2n
    • Hence, f1(n)=Θ(n)f_1(n) = \Theta(n) and f1(n)=O(n)f_1(n) = O(n).

  2. For Function_2:

    • The for loop runs directly from 11 to 100×n100 \times n.

    • Thus, f2(n)=100n=Θ(n)f_2(n) = 100n = \Theta(n).

  3. Evaluating the options:

    • Option (A): Since f1(n)=Θ(n)f_1(n) = \Theta(n) and f2(n)=Θ(n)f_2(n) = \Theta(n), we have f1(n)∈Θ(f2(n))f_1(n) \in \Theta(f_2(n)). Hence, (A) is TRUE.

    • Option (B): lim⁡n→∞f1(n)f2(n)=lim⁡n→∞Θ(n)100n≠0\lim_{n \to \infty} \frac{f_1(n)}{f_2(n)} = \lim_{n \to \infty} \frac{\Theta(n)}{100n} \neq 0. Therefore, f1(n)∉o(f2(n))f_1(n) \notin o(f_2(n)). Hence, (B) is FALSE.

    • Option (C): lim⁡n→∞f1(n)f2(n)≠∞\lim_{n \to \infty} \frac{f_1(n)}{f_2(n)} \neq \infty, so f1(n)∉ω(f2(n))f_1(n) \notin \omega(f_2(n)). Hence, (C) is FALSE.

    • Option (D): Since f1(n)<2nf_1(n) < 2n, we have f1(n)∈O(n)f_1(n) \in O(n). Hence, (D) is TRUE.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Asymptotic Analysis previous year question is Q54 of the GATE CSE 2023 paper. Find more GATE CSE PYQs on Asymptotic Analysis in Algorithms, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Asymptotic Analysis PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Asymptotic Analysis in GATE CSE

Asymptotic Analysis has 31 GATE CSE PYQs across 19 papers from 2011 to 2026. This is the only 2-mark MSQ among them, and GATE CSE 2023 has 2.

How GATE tests Asymptotic Analysis

More from GATE CSE 2023

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2023 · Q54 · MSQ

Consider functions Function\1 and Function\2 expressed in pseudocode as follows: Function1 while n > 1 do for i = 1 to n do x = x + 1; end for n = ⌊n/2⌋; end while Function2 for i = 1 to 100 * n do x = x + 1; end for Let f1(n) and f2(n) denote the number of times the statement “x = x + 1” is executed in Function\1 and Function\2, respectively. Which of the following statements is/are TRUE?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.