GateAI
Asymptotic Analysis

GATE CSE 2014 Set 1 · Q42

MCQ2 marksMedium

Time

Consider the following pseudo code. What is the total number of multiplications to be performed?D = 2 for i = 1 to n do for j = i to n do for k = j + 1 to n do D = D * 3

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C) One-sixth of the product of the 3 consecutive integers.

Asymptotic Analysis

To find the total number of multiplications, count the number of times the statement D = D * 3 is executed.

The statement executes for each combination of indices (i,j,k)(i, j, k) such that:

1≤i≤j<k≤n1 \le i \le j < k \le n

For a fixed ii and jj, kk runs from j+1j+1 to nn, which gives (n−j)(n - j) executions.

Summing over jj from ii to nn:

∑j=in(n−j)=(n−i)+(n−i−1)+⋯+1+0=(n−i)(n−i+1)2\sum_{j=i}^n (n - j) = (n - i) + (n - i - 1) + \dots + 1 + 0 = \frac{(n - i)(n - i + 1)}{2}

Now summing over ii from 11 to nn: Let p=n−ip = n - i. As ii varies from 11 to nn, pp takes values from n−1n - 1 down to 00:

Total multiplications=∑p=0n−1p(p+1)2=12∑p=1n−1p(p+1)\text{Total multiplications} = \sum_{p=0}^{n-1} \frac{p(p+1)}{2} = \frac{1}{2} \sum_{p=1}^{n-1} p(p+1)

Using the identity ∑p=1mp(p+1)=m(m+1)(m+2)3\sum_{p=1}^{m} p(p+1) = \frac{m(m+1)(m+2)}{3} with m=n−1m = n - 1:

Total multiplications=12⋅(n−1)n(n+1)3=(n−1)n(n+1)6\text{Total multiplications} = \frac{1}{2} \cdot \frac{(n-1)n(n+1)}{3} = \frac{(n-1)n(n+1)}{6}

Here, (n−1)n(n+1)(n-1)n(n+1) is the product of three consecutive integers. Thus, the total number of multiplications is one-sixth of the product of the 3 consecutive integers.

Hence, the correct option is (C).

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 Q42 of the GATE CSE 2014 Set 1 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. 12 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2014 Set 1.

How GATE tests Asymptotic Analysis

More from GATE CSE 2014 Set 1

Share this solution

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

GateAI solution cardGATE CSE 2014 Set 1 · Q42 · MCQ

Consider the following pseudo code. What is the total number of multiplications to be performed? D = 2 for i = 1 to n do for j = i to n do for k = j + 1 to n do D = D * 3

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.