Sorting, one step at a time
Pick an algorithm and step through it. Watch which line of code runs, and count the comparisons — that count is what “efficiency” really means.
- comparing
- swapping
- in final place
Turn on JavaScript to run the visualizer.
Pencil check: in sessions we do this with numbered index cards on the table first. Sort eight cards by hand using bubble sort and count your comparisons — then predict how many it takes for sixteen.