Data Structure
Sorting Algo | Time Complexity | Space Complexity |
Bubble Sort | O(n^2) | O(1) |
Selection Sort | O(n^2) | O(1) |
Insertion Sort | O(n^2) | O(1) |
Merge Sort | O(n log n) | O(n) |
Quick Sort | O(n log n) average, O(n^2) worst case (unbalanced partitions) | O(log n) average, O(n) worst case |
Heap Sort | O(n log n) | O(1) |
Radix Sort | O(nk), where k is the number of digits | O(n + k) |
Counting Sort | O(n + k), where k is the range of input values | O(k) |
Bucket Sort | O(n + k), where k is the number of buckets | O(n + k) |
Shell Sort | Depends on the gap sequence; worst-case is generally considered to be O(n^2) | O(1) |