Input
Speed
Algorithms
unsortedcomparingwritingin final position
Step 1 / 78 · narration

Quick sort: pick a pivot, move everything smaller to its left, then recurse on each side.

comparisons0writes0in place0/16
Quick sortdivide and conquer

Usually the fastest in practice thanks to cache behaviour, but the worst case is real without a good pivot.

Complexity
bestO(n log n)
averageO(n log n)
worstO(n²)
spaceO(log n)
Good for
  • Usually fastest in practice: sequential access, no scratch array
  • Each pass settles one pivot permanently
Watch out
  • O(n²) when the pivot keeps splitting one-against-the-rest
  • Sorted input is that worst case, for a last-element pivot
On this exact input
AlgorithmComparisonsWritesWorst case
Bubble sort117114O(n²)
Selection sort12026O(n²)
Insertion sort6972O(n²)
Merge sort4664O(n log n)
Quick sort4246O(n²)
Heap sort85112O(n log n)
Counting sort016O(n + k)

Counting sort runs on a smaller value range than the others, since it needs one bucket per distinct value.

Sorting Algorithm Visualizer · Built with Nandscape