GATE / CS ARCHIVE

GATE CSE 2006 / QUESTION 14

Sorting with few swaps

Algorithms · Searching, Sorting & Selection · Full GATE CSE 2006 paper

GATE 2006, Q14 1 mark · MCQ
Report issue

Searching, Sorting & Selection

Question 14, GATE 2006: Among the standard in-place sorting algorithms listed, which needs the fewest swaps under the conventional worst-case exchange-count comparison?
Options:
(A) Quicksort
(B) Insertion sort
(C) Selection sort
(D) Heapsort
Tap to enlarge
Your answer
Answer & solution

Answer: C under the standard swap-based comparison (no official key was published)

1. Selection sort places the minimum remaining item in its final location with at most one exchange per pass, hence at most n−1 swaps. Standard swap-based insertion sort, quicksort and heapsort can use more.

2. Thus selection sort, C, in the conventional worst-case exchange-count comparison. A shift-based insertion implementation can avoid an explicit swap operation, so literal source-code swap counts are implementation-dependent.

3. Teaching check: Selection sort can inspect the entire unsorted suffix without moving any item, then exchange its minimum with the first unsorted position. This separates comparison count, Θ(n²), from exchange count, O(n). The question asks about swaps, not fastest running time.

Original paper, page 2