Gradient LabSign up free

Home / GATE DA / 2025 / Q.29

GATE DA 2025, Q.29: Values of x giving exactly two swaps

Data structures and algorithmsInsertion sort swaps1 markMSQ (more than one correct)Free

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?

Watch it solved

Solve it step by step

  1. Swaps = inversions. Insertion sort makes one swap per out-of-order pair.
  2. Fixed inversion. 15 before 13 is always one.
  3. Need one more. x = 10: one with 11. x = 12: none. x = 14: one with 13. x = 16: two (with 15 and 13).
  4. 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 sheets

Source: official GATE DA 2025 question paper and answer key (IIT Roorkee). The question is lightly reworded; every number and option is kept.