pivot
comparing
swapping
sorted
5
0
3
1
8
2
1
3
9
4
2
5
7
6
4
7
Pick a pivot. Partition: smaller values left, larger right. Recurse on each half.
Like sorting cards — pick one as reference, put smaller ones before it, bigger ones after.
start
1 / 69
SPD0.5×
click to pause · hover for controls · fullscreen for more

Quick Sort

Pick a pivot, partition, repeat — sorting at its fastest

Visual by thisgirltech

IntermediateSorting

Quick Sort is a divide-and-conquer sorting algorithm that works by selecting a pivot element and partitioning the array into two halves — elements smaller than the pivot go left, elements larger go right.

It then recursively sorts each half. Despite an O(n²) worst case, Quick Sort is one of the fastest sorting algorithms in practice due to excellent cache performance and low overhead.

Fast in practice

Outperforms Merge Sort and Heap Sort in real-world scenarios due to better cache locality.

Divide & conquer

Pick a pivot, partition around it, then recursively sort each side.

In-place

Sorts without requiring extra array space — only O(log n) stack space for recursion.

TIP

Pivot choice matters — always picking the first or last element can degrade to O(n²) on sorted arrays. Median-of-three or random pivot selection avoids this.

COLOUR LEGEND

Pivot
Comparing
Swapping
Active partition
Sorted