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

Quicksort uses the Lomuto partition with the last element as pivot on [34, 6, 22, 26, 49, 1, 18]. After one partition call, at which index (0-based) does the pivot end up?

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

Correct answer: C. 2

The pivot 18 ends at index = count of elements ≤ 18 before it = 2. Array after partition: [6, 1, 18, 26, 49, 34, 22].

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

Exams that ask this topic