The idea
Key formulas
Quadratic comparison bound
Loading lessons…
Just a moment, getting everything ready. The first load can take up to a minute.
Data structures and algorithms
Compare bubble, insertion, and selection sort by tracing comparisons and swaps on the same input.
Bubble sort repeatedly compares neighbors, insertion sort grows a sorted prefix, and selection sort finds the next minimum. Their simple implementations are usually quadratic, but input order and the exact operation counted affect the observed work.
The counters show comparisons and swaps for all three algorithms; choose one to inspect its individual steps. Insertion sort can be efficient on nearly sorted data, while selection sort performs few swaps.