Quick Sort

Watch quicksort partition bars around a pivot — small left, big right. Average O(n log n) and usually fastest, but watch the reversed array degrade to O(n²).

Algorithm

Array

Size48
ComparingSwap/writePivot/keyReadSorted
Speed50×

Comparisons

0

Swaps/writes

0

Step

0/467

Reads

0

Aux memory

0

Call depth

1/1

Slow the speed and use Step to match the pseudocode highlight with the bar colors.

Pseudocode

quickSort(lo, hi)

pivot ← a[hi]

for j ← lo to hi−1

if a[j] ≤ pivot: a[i++] ↔ a[j]

a[i] ↔ a[hi] // 피벗 확정

quickSort(lo,i−1) quickSort(i+1,hi)

Time complexity

BestO(n log n)
AverageO(n log n)
WorstO(n²)
SpaceO(log n)
StableNo

Quicksort picks a pivot (purple bar), partitions the array so smaller values go left and larger go right, then recurses on each side. The pivot's final position locks in after each partition.

Balanced pivots give log n depth → average O(n log n) with excellent cache locality, which is why most built-in sorts are quicksort-based. But an always-worst pivot (e.g. last element on a reversed array) degrades to O(n²) — try the Reversed preset to see it happen. Sorting Visualizer

Frequently asked questions

Why is quicksort the standard if it can hit O(n²)?
Random or median-of-three pivots make the worst case practically impossible, and its average speed plus cache behavior beats other O(n log n) sorts. Some implementations switch to heapsort on bad partitions (Introsort).
Is quicksort stable?
No — partitioning swaps distant elements, so equal values can be reordered.

Other algorithms