Using the comparison
Type a list, then choose a sort in the To box. The animation below plays that algorithm on your list, and switching the sort switches the animation, so you can watch the same list sorted six different ways. Each sort also has its own page, with more on how it works.
Comparisons for ten numbers
| Algorithm | Shuffled | Already sorted | Reversed | Keeps equal items in order |
|---|---|---|---|---|
| Bubble sort | 39 | 9 | 45 | Yes |
| Selection sort | 45 | 45 | 45 | No |
| Insertion sort | 31 | 9 | 45 | Yes |
| Merge sort | 24 | 19 | 15 | Yes |
| Quick sort | 23 | 45 | 45 | No |
| Heap sort | 37 | 41 | 35 | No |
Comparisons for ten numbersstringmash.com/sorting-algorithms
Reading the table
Each number is how many comparisons that sort makes on ten numbers: shuffled, already in order, and in reverse. They're measured by running the same code the animations use, so they're exactly what you'd count by stepping through.
Bubble sort and insertion sort shine on a list that's already sorted, finishing in nine comparisons. Selection sort makes 45 whatever it's given. Quick sort, picking the last item as its pivot, is fastest on the shuffled list and slowest on the ordered ones. Merge sort and heap sort stay steady.
The last column is whether two equal items stay in the order they started in, tested on several lists with repeats.
Each sort on its own page
8 converters in 2 groups
- Bubble sort5 3 1becomes1 3 5Compare neighbours and swap, pass after pass.
- Selection sort29 10 14becomes10 14 29Find the smallest left and move it to the front.
- Insertion sort12 11 13becomes11 12 13Slide each item left into place, like cards in a hand.
- Merge sort38 27 43becomes27 38 43Split in half, sort each half, merge them back.
- Quick sort10 80 30becomes10 30 80Split around a pivot, then sort each side.
- Heap sort4 10 3becomes3 4 10Build a heap, then take the biggest off it each time.
Nothing here matches that. If you're holding text you can't read, the cipher identifier tries every converter on it.
Questions
Which sorting algorithm is fastest?
For long lists, merge sort, heap sort and a well-built quick sort, which all grow with n log n rather than n². Quick sort is often quickest in practice. For short or nearly sorted lists, insertion sort can beat all of them.
What does O(n log n) mean?
That the work grows a little faster than the length of the list. Doubling the list slightly more than doubles the work. O(n²) means doubling the list quadruples it.
Why does the animation only go up to 3 steps a second?
Each step recolours a bar or two, and three changes a second is the limit the web's accessibility guidelines set for anything that flashes. Step forward goes as fast as you can click.






