AlgoFrames

Partition by hand

Warm-up · Trace the algorithm · about 6 min

Follow the Lomuto partition on [8, 3, 9, 1, 6, 2, 7, 5]. The pivot is the last value, 5. Before each swap plays, arrange the values as they look afterwards.

Example 1

Input:

{"values":[8,3,9,1,6,2,7,5]}

Output:

[3,1,2,5,6,9,7,8]

Smaller values end left of the pivot, the rest right.

Constraints

  • The trace uses the input shown.

Learn the idea first: Quick sort: partitioning and pivots, a visual lesson.

More Quick sort: partitioning and pivots problems