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

Quicksort with Lomuto partitioning (last element as pivot) sorts [84, 38, 96, 7, 19, 64, 7, 94]. How many swaps happen in total, across all recursive calls?

  1. A. 8
  2. B. 9
  3. C. 10
  4. D. 11

Correct answer: B. 9

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 9 swaps.

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

Exams that ask this topic