GateAI
Sorting

GATE CSE 2021 Set 1 · Q9

MCQ1 markEasy

Time

Consider the following array. Which algorithm out of the following options uses the least number of comparisons (among the array elements) to sort the above array in ascending order?

GATE CSE 2021 Set 1 Q9 diagram

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C) Insertion sort

Sorting

The given array is already sorted in ascending order:

[23,32,45,69,72,73,89,97][23, 32, 45, 69, 72, 73, 89, 97]

Here, the number of elements is n=8n = 8.

Let us analyze the number of comparisons for each algorithm on an already sorted array:

  1. Insertion sort: In the best case (when the array is already sorted), each element from index 11 to n−1n-1 is compared only once with its immediate predecessor to determine that it is already in the correct position. The total number of comparisons is:

n−1=8−1=7n - 1 = 8 - 1 = 7
  1. Selection sort: It always scans the remaining unsorted subarray to find the minimum element, regardless of the initial order. It requires:

n(n−1)2=8×72=28 comparisons\frac{n(n-1)}{2} = \frac{8 \times 7}{2} = 28\text{ comparisons}
  1. Mergesort: The standard mergesort divides the array recursively and merges sorted subarrays. Even in the best case, it requires Θ(nlog⁡2n)\Theta(n \log_2 n) comparisons (at least 1212 comparisons for n=8n=8).

  2. Quicksort (last element as pivot): Since the array is already sorted and the pivot is chosen as the last element, the pivot is always the largest element in the current partition. This leads to the worst-case unbalanced recursion tree of depth nn, requiring:

n(n−1)2=28 comparisons\frac{n(n-1)}{2} = 28\text{ comparisons}

Hence, Insertion sort (Option C) uses the least number of comparisons.

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 Sorting previous year question is Q9 of the GATE CSE 2021 Set 1 paper. Find more GATE CSE PYQs on Sorting 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 3 related Sorting 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.

Sorting in GATE CSE

Sorting has 3 GATE CSE PYQs across 3 papers from 2015 to 2025. 2 of them are 1-mark MCQs like this one, and it is the only one in GATE CSE 2021 Set 1.

How GATE tests Sorting

More from GATE CSE 2021 Set 1

Share this solution

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

GateAI solution cardGATE CSE 2021 Set 1 · Q9 · MCQ

Consider the following array. Which algorithm out of the following options uses the least number of comparisons (among the array elements) to sort the above array in ascending order?

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.