GATE Computer ScienceHardNIELIT Scientist B

Quicksort uses the last element of each sub-array as pivot and compares every other element of the sub-array with it once. On [4, 7, 1, 9, 3, 8, 2, 6, 5] how many key comparisons are made in total?

  1. A. 14
  2. B. 20
  3. C. 23
  4. D. 17

Correct answer: D. 17

Summing (size − 1) over every partitioned sub-array in the recursion gives 17.

More Algorithms questions

Exams that ask this topic