Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE

Quicksort uses the Lomuto partition with the last element as pivot on [32, 14, 29, 16, 25, 12, 11, 13, 31]. After one partition call, at which index (0-based) does the pivot end up?

  1. A. 11
  2. B. 6
  3. C. 7
  4. D. 14

Correct answer: C. 7

The pivot 31 ends at index = count of elements ≤ 31 before it = 7. Array after partition: [14, 29, 16, 25, 12, 11, 13, 31, 32].

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

Exams that ask this topic