GATE Computer ScienceVery hardGATE CSE

Quicksort with Lomuto partitioning (pivot = last element of the sub-array, loop compares A[j] ≤ pivot for j from lo to hi−1) sorts [4, 9, 2, 7, 1, 8, 3, 10, 5, 6]. How many element-versus-pivot comparisons (A[j] ≤ pivot) are made in total across all partition calls?

  1. A. 21
  2. B. 25
  3. C. 18
  4. D. 29

Correct answer: A. 21

Each partition of a sub-array of size m costs m−1 comparisons; following the recursion splits gives 21.

More Programming and Data Structures (GATE) questions

Exams that ask this topic