Skip to content
BENIBIX Learn

Quicksort

Development🧮 Algorithms & Data StructuresSorting Algorithms

Also known as Quick Sort, Partition-Exchange Sort

A fast sort. It splits items around a pivot, then sorts each side.

Think of it like

Think of it like lining up kids. Pick one kid; short kids go left, tall kids go right.

Example

Emma's quicksort picks 5 as the pivot for 8, 3, 5, 9, 1. It moves 3 and 1 left and 8 and 9 right, then sorts each side.

Why it matters

It is one of the fastest sorts in real use, and many built-in sorts start from it.

Definition

Quicksort picks one item, called the pivot, and puts smaller items to its left. Larger items go to its right. Then it does the same to each side, until every piece is sorted. It sorts in place, so it needs little extra memory. On average it takes O(n log n) steps and is very fast in practice. With a bad pivot every time, it slows to O(n²).

Common mistake

Always picking the first item as the pivot. On a list that is already sorted, that hits the slow O(n²) case.

Key takeaways

  1. 1
    Pick a pivot. Smaller left, larger right.
  2. 2
    Repeat on each side. Until all is sorted.
  3. 3
    Fast on average. Slow with bad pivots.

Compare