Compare algorithms
Run several algorithms on the same input, side by side, and see where each one wins.
0 / 429 steps
Bubble sort 0 comparisons · 0 moves
Insertion sort 0 comparisons · 0 moves
Merge sort 0 comparisons · 0 moves
Quicksort 0 comparisons · 0 moves
- comparing
- moving
- in final place
- in hand / pivot
- sorted part
Every step is one comparison or one move in each run, so the run that finishes first did the least work.
Space: play or pause. Left and right arrows: step. Home and End: jump.
What the comparison shows
Quadratic sorts such as bubble, insertion and selection sort make about n²/2 comparisons on random data, while merge sort, quicksort and heapsort stay close to n log₂ n. The shape of the input changes the picture: insertion sort needs little more than n comparisons on nearly sorted data, while quicksort depends on how evenly its pivots split the values.