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

Quicksort uses the Lomuto partition with the last element as pivot on [7, 15, 50, 22, 27, 13, 16]. After one partition call, at which index (0-based) does the pivot end up?

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

Correct answer: B. 3

The pivot 16 ends at index = count of elements ≤ 16 before it = 3. Array after partition: [7, 15, 13, 16, 27, 50, 22].

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

Exams that ask this topic