ProgrammingVery hard

Insertion sort (shift larger elements right, then place the key) is applied to {4, 1, 3, 2}. How many element shifts happen in total?

  1. A. 3
  2. B. 5
  3. C. 4
  4. D. 6

Correct answer: C. 4

Each shift removes one inversion, and the input has 4 inversions: (4,1), (4,3), (4,2) and (3,2).

More C Programming questions

Exams that ask this topic