A041 · Computer science
How sorting algorithms work
Twelve numbers, three strategies. Watch comparisons and swaps one at a time: the same starting array makes the algorithms easy to compare fairly.
What are you seeing?
Each bar represents one array element. Orange bars are being compared; when two elements swap, they move to their new positions. The counters distinguish comparisons from swaps.
Ready: press Play or Next step.
Comparisons0
Swaps0
Step0 / 0
Starting array:
Current array:
Each visual step takes one second by default. The step count includes comparisons and swaps; it does not measure a program’s actual execution time.
Bubble Sort
Compare neighbours and swap them when they are out of order. After each pass, the largest remaining value reaches its final position.
Compare them
Press Restart, select another algorithm and play again: the 12 numbers remain the same. Only “New numbers” changes the array.