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?
- A. 11
- B. 6
- C. 7
- 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].
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Two sorted lists [10, 16, 17, 27, 29] and [16, 20, 22, 25] are merged using the standard merge step. How many element comparisons are made?
- A queue is implemented with two stacks (enqueue pushes to stack "in"; dequeue pops from stack "out", refilling "out" from "in" by…
- What is the postfix (Reverse Polish) form of the infix expression "(c + i) a - j / d", built with the standard stack-based conversion (^…
- The Dutch National Flag algorithm (single pass, three pointers low/mid/high) partitions [1, 0, 1, 2, 2, 2, 1, 1] (values 0, 1, 2 only) in…
- Elevation map [6, 1, 1, 0, 3, 3, 5, 5, 2, 0] (bar width 1). Using the two-pointer / prefix-max approach for trapping rain water, how much…
- Array [75, 79, 80, 82, 6, 11, 23, 40, 63, 67] is a sorted array rotated at pivot 6. Using the standard O(log n) rotated-array binary…