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?
- A. 4
- B. 3
- C. 9
- 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].
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
- Evaluate the postfix expression: 1 1 - 5 9 + 9 +
- How many swaps does bubble sort (adjacent swaps, ascending) make on [27, 39, 17, 5, 21, 29, 48, 12, 41]?
- A sorted array holds the 31 values 2, 5, 8, … (step 3). Binary search with mid = ⌊(lo+hi)/2⌋ and 0-based indices looks for 17. How many…
- Keys 88, 69, 39, 31, 97 are inserted into a hash table of size 8 with h(k) = k mod 8 and linear probing. At which index is 97 stored?
- A circular queue is implemented in an array of size 11 with front = 10 and rear = 2 (rear indexes the last stored element, the queue is…
- 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…