Compare every algorithm
Click any column to sort. Click a row to open the algorithm.
| Algorithm | Best | Average ↑ | Worst | Memory | Stable | Recursive | Cache friendly | Adaptive | Typical usage |
|---|---|---|---|---|---|---|---|---|---|
| Counting Sort | O(n + k) | O(n + k) | O(n + k) | O(n + k) | yes | — | yes | — | Small integer keys; radix building block |
| Bucket Sort | O(n + k) | O(n + k) | O(n²) | O(n + k) | yes | — | — | — | Uniformly distributed floats |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) | O(n) | yes | yes | — | — | External sorting; linked lists; stable sorts |
| Quick Sort | O(n log n) | O(n log n) | O(n²) | O(log n) | — | yes | yes | — | General-purpose in-memory sorting |
| Heap Sort | O(n log n) | O(n log n) | O(n log n) | O(1) | — | — | — | — | Worst-case guarantees; constant memory |
| Tim Sort | O(n) | O(n log n) | O(n log n) | O(n) | yes | — | yes | yes | Stdlib default (Python, Java, V8) |
| Bubble Sort | O(n) | O(n²) | O(n²) | O(1) | yes | — | yes | yes | Teaching; detecting already-sorted data |
| Selection Sort | O(n²) | O(n²) | O(n²) | O(1) | — | — | yes | — | Minimizing writes (EEPROM/flash) |
| Insertion Sort | O(n) | O(n²) | O(n²) | O(1) | yes | — | yes | yes | Small or nearly-sorted arrays; sort cutoffs |
| Shell Sort | O(n log n) | O(n^1.25) – O(n^1.5) | O(n²) | O(1) | — | — | yes | yes | Embedded; mid-size arrays without recursion |
| Radix Sort | O(d · (n + k)) | O(d · (n + k)) | O(d · (n + k)) | O(n + k) | yes | — | — | — | Fixed-width keys: ints, strings, IPs |