Data Structures & AlgorithmsVery hardGATE CS · TCS NQT · Product Company SDE

Quicksort with Lomuto partitioning (last element as pivot) sorts [12, 42, 92, 73, 37, 39, 75, 75, 32]. How many swaps happen in total, across all recursive calls?

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

Correct answer: B. 4

Each partition call swaps a[i] with a[j] whenever a smaller-or-equal element is found, plus the final pivot swap; summed over all recursive calls this totals 4 swaps.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic