sort.cny.shStart a race
Back to library
08 / 18Algorithm

Quick Sort

Pick a pivot, partition, recurse. Fast in practice.

StableIn-placeUnstable
BestO(n log n)
AverageO(n log n)
WorstO(n²)
01How it works

Pick a pivot, partition the array so smaller values sit left and larger right, then recurse on each side. The partition does the heavy lifting; the recursion is often implemented with one real call and one tail call to keep the stack small.

02Best for

General-purpose in-memory sorting of large arrays. Excellent cache behavior and tiny constants make it the fastest option in practice on random data — C's qsort and the unstable sort in many language runtimes are quicksort variants.

03Avoid when

Adversarial or already-sorted input with a naive pivot choice collapses to O(n²). It also isn't stable — reach for mergesort or TimSort when equal-key order must be preserved.