Sorting

Watch sorting algorithms run one operation at a time: which values get compared, which ones swap, and how the array settles into order.

Visualisations

Bubble Sort

Watch bubble sort compare adjacent pairs and swap until the largest value reaches the end. Step through it one comparison at a time, or try your own numbers.

avgO(n²)spaceO(1)stableyes
Open visualiser

Insertion Sort

Watch insertion sort grow a sorted prefix one value at a time, shifting larger values right to make room. Step through each comparison or try your own numbers.

avgO(n²)spaceO(1)stableyes
Open visualiser

Selection Sort

Watch selection sort scan for the smallest value and swap it into place, one pass at a time. Step through every comparison, or try your own numbers.

avgO(n²)spaceO(1)
Open visualiser

Merge Sort

Watch merge sort halve an array, sort each half, then merge the two sorted runs back into one. Step through every comparison, or try your own numbers.

avgO(n log n)spaceO(n)stableyes
Open visualiser

Quick Sort

Watch quick sort pick a pivot, partition the array around it, then recurse on both halves. Step through every comparison and swap, or try your own numbers.

avgO(n log n)spaceO(log n)
Open visualiser

Heap Sort

Watch heap sort build a max-heap and extract the largest value one at a time. Step through every comparison and swap, or try your own numbers.

avgO(n log n)spaceO(1)
Open visualiser

Radix Sort

Watch radix sort distribute values into digit buckets and collect them back, one digit at a time. Step through every placement, or try your own numbers.

avgO(nk)spaceO(n + b)stableyes
Open visualiser

Counting Sort

Watch counting sort count occurrences, build prefix sums, then place each value at its final position. Step through every operation, or try your own numbers.

avgO(n + k)spaceO(n + k)stableyes
Open visualiser

Thanos Sort

Watch Thanos sort snap away half the array until what remains is sorted. A joke algorithm that solves the sorting problem by eliminating the data.

avgO(n log n)spaceO(n)
Open visualiser

Side by side

AlgorithmBestAverageWorstSpaceStable
Bubble SortO(n)O(n²)O(n²)O(1)Yes
Insertion SortO(n)O(n²)O(n²)O(1)Yes
Selection SortO(n²)O(n²)O(n²)O(1)No
Merge SortO(n log n)O(n log n)O(n log n)O(n)Yes
Quick SortO(n log n)O(n log n)O(n²)O(log n)No
Heap SortO(n log n)O(n log n)O(n log n)O(1)No
Radix SortO(nk)O(nk)O(nk)O(n + b)Yes
Counting SortO(n + k)O(n + k)O(n + k)O(n + k)Yes
Thanos SortO(n)O(n log n)O(n log n)O(n)No