Using Lomuto partitioning with the last element as pivot, what is the array after one partition step?
Correct answer B. [3, 1, 4, 8, 9, 7]
Explanation
The pivot is 4. Scanning left to right, elements not greater than 4 are swapped into the growing left region: 3 swaps with 8, giving [3, 8, 7, 1, 9, 4], then 1 swaps with 8, giving [3, 1, 7, 8, 9, 4]. Finally the pivot swaps with 7 into index 2: [3, 1, 4, 8, 9, 7]. Partitioning places the pivot correctly but leaves both sides unsorted.
Answer checked How we write and check questions
Discussion