← Back to the sorting page
Simple Quadratic Sorts
Bubble, selection, and insertion sort. Insertion sort is the one that survives in production — as the small-array finisher inside faster sorts.
What to know
- Insertion sort is O(n + inversions): nearly-sorted data sorts in near-linear time.
- Selection sort makes the minimum number of swaps — relevant when writes are expensive.
- Standard libraries switch to insertion sort below ~16–32 elements.
In the wild: The base case inside quicksort/Timsort, sorting hands of cards, tiny embedded systems.
Algorithms to reach for
Insertion sort
O(n²), O(n) bestSmall or nearly-sorted arrays, online insertion
Selection sort
O(n²)Minimize swap count on write-costly media
Practice problems — with full guides
Each problem has its own page: progressive hints, how to approach it, and the full solution.