GATE DA 2025, Q.29: Values of x giving exactly two swaps
The question
Insertion sort is applied to [1, 3, 5, 7, 9, 11, x, 15, 13] and needs exactly two swaps. Which x are possible?
- (A) 10
- (B) 12
- (C) 14
- (D) 16
Watch it solved
Solve it step by step
- Swaps = inversions. Insertion sort makes one swap per out-of-order pair.
- Fixed inversion. 15 before 13 is always one.
- Need one more. x = 10: one with 11. x = 12: none. x = 14: one with 13. x = 16: two (with 15 and 13).
- Answer. x = 10 or 14.
Answer: A, C
Official IIT Roorkee answer key: A; C.
Common mistake. Only checking x against its left neighbour, and missing that a large x also inverts with later elements.
Remember. Number of insertion-sort swaps = number of inversions.
Want every question solved? The past-paper pack has all 195 questions from 2024, 2025 and 2026 for ₹499. The cheat sheet pack has 23 printable sheets for ₹399.
See the past-paper pack See the cheat sheetsSource: official GATE DA 2025 question paper and answer key (IIT Roorkee). The question is lightly reworded; every number and option is kept.