Sorting
Sorting algorithms are a set of techniques used to arrange elements, with each algorithm having its own strengths and weaknesses, making it suitable for different scenarios and types of data.
| Name | Stable? | Time | Space |
|---|---|---|---|
| Bubble Sort | Yes | O(n^2) | O(1) |
| Selection Sort | No | O(n^2) | O(1) |
| Insertion Sort | Yes | O(n^2) | O(1) |
| Merge Sort | Yes | O(n log(n)) | O(n) |
| Quick Sort | No | O(n log(n)) (worst: O(n^2)) | O(log(n)) |
| Counting Sort | Yes | O(n + k) | O(k) |
| Radix Sort | Yes | O(nk) | O(n + k) |
| Heap Sort | No | O(n log(n)) | O(1) |
- Stable: Equal elements keep their original order.
- Unstable: Equal elements might not keep their original order.