GATE DA 2025 Q29: Insertion sort with exactly two swaps: possible values of x
- Programming, Data Structures and Algorithms
- 1 mark
- MSQ
- No negative marking
Question
Suppose that insertion sort is applied to the array and it takes exactly two swaps to sort the array. Select all possible values of .
Try it: multiple select: one or more correct options
Show answer and explanation
Answer: A, C (official GATE 2025 final answer key)
Concept used: The number of swaps in insertion sort equals the number of inversions in the array.
First step: The pair (15, 13) is already one inversion, so must create exactly one more. Count the inversions forms with the elements before and after it.
Full step-by-step solution
Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.
Share this question
Source: official GATE 2025 DA question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key
More Programming, Data Structures and Algorithms PYQs
- 2025 · Q18Hashing with linear probing: h(x) = 3x mod 10
- 2025 · Q23Python lists: which call gives A = [1, 2, 3, 4, 5, 6]?
- 2025 · Q27When does binary search run in O(log n)?
- 2025 · Q47Python sets in a while loop: which set ends up with "this"?
- 2025 · Q58Shortest paths: which edges cannot be in G?
- 2025 · Q63Python recursion: value of f(15, 10)