algo·visual

Quick Sort

Sorting
avgO(n log n)worstO(n²)spaceO(log n)
58
39
11
9
8
5
13
38
58
87
67
77
32
20
58
39
59
63
16
66
46
67
37
14
  • Waiting
  • Current range
  • Just swapped
  • In final position

Start with 24 unsorted values

1 / 217
Size24
Distribution
Custom values2 to 150 whole numbers, each 1 to 999

seed 13

Growth by input size

Averaged over seeded runs for each size. Random, Nearly sorted and Reversed use distinct values (the site's own inputs pick values from 5 to 99, so they repeat even in small arrays), so the curves follow the textbook cases. Sizes above 150 are only for this chart; the animation stops at 150.

How it works

Picks the last element as a pivot and partitions the range so smaller elements land to its left (Lomuto scheme); the pivot is then in its final place and both sides are sorted recursively. It is fast in practice, but a bad run of pivots slows it to O(n²).

Complexity

Best
O(n log n)
Average
O(n log n)
Worst
O(n²)
Space
O(log n)
Stable
No
In place
Yes

Search algorithms

Jump to any algorithm or page