Quicksort

Put a row of number cards in order. Pick the last card and gather all cards with smaller numbers to its left.

The chosen number is the pivot. The scan pointer visits each card and split marks where the next smaller card belongs.

Put the pivot at the boundary. It is now in its final place. Sort the two remaining groups the same way.

Sorting takes O(n log n) time on average. If the pivot is always the largest card, the range shrinks by just one each time and sorting takes O(n²).