⚡ Sorting Algorithm Complexity 📖
Best, average, and worst case complexity and stability for Quick Sort, Merge Sort, Timsort, Heap Sort, and every other major sorting algorithm — quick revision notes.
⚡ Sorting Algorithm Complexity
| # | Algorithm | ⏱️ Best | ⚖️ Average | 🔻 Worst | 💾 Space | ⚙️ Stability |
|---|---|---|---|---|---|---|
| 1 | ⚡ Quick Sort | ❌ No | ||||
| 2 | 🧩 Merge Sort | ✅ Yes | ||||
| 3 | 🚀 Timsort | ✅ Yes | ||||
| 4 | ⛰️ Heap Sort | ❌ No | ||||
| 5 | 💧 Bubble Sort | ✅ Yes | ||||
| 6 | ✍️ Insertion Sort | ✅ Yes | ||||
| 7 | 🪞 Selection Sort | ❌ No | ||||
| 8 | 🌲 Tree Sort | ❌ No | ||||
| 9 | 🐚 Shell Sort | * | ~ | ❌ No | ||
| 10 | 🪣 Bucket Sort | ✅ Yes** | ||||
| 11 | 🔢 Radix Sort | ✅ Yes | ||||
| 12 | 🧮 Counting Sort | ✅ Yes |
Notes
- k = range of keys (Counting/Bucket Sort) or number of digits (Radix Sort).
- *Shell Sort's complexity depends on the gap sequence; there is no universally accepted average-case complexity.
- Bucket Sort is stable only if the sorting algorithm used within each bucket is stable (e.g., Insertion Sort).
Related Posts
- 🧱 Data Structures & Big O Complexity — the Big O/Big Omega/Big Theta notation used throughout this comparison
- 🔎 Searching Algorithm Complexity — Binary Search and other sorted-data-dependent searches this sorting step enables
