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.
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.
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.
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.
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.
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.
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.
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.
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.
Side by side
| Algorithm | Best | Average | Worst | Space | Stable |
|---|---|---|---|---|---|
| Bubble Sort | O(n) | O(n²) | O(n²) | O(1) | Yes |
| Insertion Sort | O(n) | O(n²) | O(n²) | O(1) | Yes |
| Selection Sort | O(n²) | O(n²) | O(n²) | O(1) | No |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) | O(n) | Yes |
| Quick Sort | O(n log n) | O(n log n) | O(n²) | O(log n) | No |
| Heap Sort | O(n log n) | O(n log n) | O(n log n) | O(1) | No |
| Radix Sort | O(nk) | O(nk) | O(nk) | O(n + b) | Yes |
| Counting Sort | O(n + k) | O(n + k) | O(n + k) | O(n + k) | Yes |
| Thanos Sort | O(n) | O(n log n) | O(n log n) | O(n) | No |