Computer Science EngineeringHardISRO SC (CS)

Insertion sort (scanning the sorted prefix from right to left, stopping at the first element not greater than the key) is run on [9, 7, 19, 36, 31, 34, 18, 23]. The number of key comparisons is:

  1. A. 10
  2. B. 18
  3. C. 17
  4. D. 16

Correct answer: D. 16

Comparisons = inversions + (number of keys that stop at an element, i.e. those with a smaller element to their left) = 16; inversions alone = 10.

More Algorithms, Data Structures & Programming (ISRO CS) questions

Exams that ask this topic