Practice mode Data Structures

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.