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?
- A. 0
- B. 5
- C. 2
- 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].
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
- How many swaps does bubble sort (adjacent swaps, ascending) make on [45, 37, 10, 17, 54, 53, 2]?
- A sorted array holds the 25 values 2, 5, 8, … (step 3). Binary search with mid = ⌊(lo+hi)/2⌋ and 0-based indices looks for 35. How many…
- Keys 64, 41, 52, 49, 80, 69, 89, 86 are inserted into a hash table of size 9 with h(k) = k mod 9 and linear probing. At which index is 80…
- A circular queue is implemented in an array of size 6 with front = 4 and rear = 0 (rear indexes the last stored element, the queue is…
- 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…
- 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?