Objective
Run bubble, selection, insertion, merge and quick sort on the same array and watch swaps, comparisons and the sorted frontier build step by step.
The idea
The array is shuffled. Pick an algorithm, step through it, and watch how each technique decides where the next element belongs. The same data makes the differences obvious.
Try this
- 1Run bubble sort on a near-sorted array and count the wasted passes.
- 2Compare quick sort's pivot choice on the same data.
- 3Step one swap at a time and predict the next move.
- 4Reset to a reversed array and watch each algorithm struggle or shine.
Watch for
- Every comparison is one step; every swap is another - that is where the cost hides.
- Bubble sort drags the largest value to the end each pass.
- Merge sort splits in half before comparing anything.
- The sorted frontier grows from different ends in each algorithm.