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
GATE CSE 2021 Set 1 · Q9
Time

Select one answerSingle correct
Solution
Official answer: C) Insertion sort
SortingThe given array is already sorted in ascending order:
Here, the number of elements is .
Let us analyze the number of comparisons for each algorithm on an already sorted array:
Insertion sort: In the best case (when the array is already sorted), each element from index to is compared only once with its immediate predecessor to determine that it is already in the correct position. The total number of comparisons is:
Selection sort: It always scans the remaining unsorted subarray to find the minimum element, regardless of the initial order. It requires:
Mergesort: The standard mergesort divides the array recursively and merges sorted subarrays. Even in the best case, it requires comparisons (at least comparisons for ).
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 , requiring:
Hence, Insertion sort (Option C) uses the least number of comparisons.
Try the question first, then check your work.
Examiner trap
Notice that the input array is already sorted in ascending order. Think about which sorting algorithm achieves its best-case running time with comparisons when the input is pre-sorted.
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
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.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
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 SortingIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.