Compare simple and efficient sorts.
Simple — O(n²)
- Bubble sort — adjacent pairs are swapped; a textbook example, not used in practice.
- Selection sort — find the minimum and put it in place; always O(n²), but the fewest swaps.
- Insertion sort — insert each element into the sorted prefix. Adaptive: O(n) on nearly sorted data, stable, no extra memory. That is why "big" sorts use it internally for short runs (≈ up to 20 elements).
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep