Bubble Sort vs Selection Sort
Across our 3 test inputs, both made the same number of comparisons (135). Bubble Sort is stable; Selection Sort is not.
Head-to-head on identical inputs (comparisons)
| Input | Bubble Sort | Selection Sort |
|---|---|---|
| Random order | 45 | 45 |
| Nearly sorted | 45 | 45 |
| Reversed | 45 | 45 |
Complexity
| Bubble Sort | Selection Sort | |
|---|---|---|
| Average time | O(n²) | O(n²) |
| Worst time | O(n²) | O(n²) |
| Space | O(1) | O(1) |
| Stable | Yes | No |
When to use Bubble Sort
Educational purposes and very small arrays. Never use in production due to O(n²) worst-case.
When to use Selection Sort
When memory writes are expensive (minimizes swaps). Otherwise, insertion sort is generally preferred.