Skip to content
StackDecode
SortingAnimated

Quick Sort

Partition around a pivot, then sort each side.

Time

O(n log n) avg, O(n²) worst

Extra space

O(log n)

Use it for

General-purpose in-memory sorting.

How it works

  1. Choose a pivot (here the last item).
  2. Partition: move smaller items to its left and larger to its right.
  3. The pivot is now in its final position.
  4. Recursively sort the left and right parts. Average O(n log n); worst O(n²) with bad pivots.

Watch it run

Loading animation…