Sorting Algorithms - Time and Space Complexities
Algorithm Best Average Worst Space Description
Bubble Sort O(n) O(n²) O(n²) O(1) Swaps adjacent elements repeatedly.
Selection Sort O(n²) O(n²) O(n²) O(1) Selects min element and places at front.
Insertion Sort O(n) O(n²) O(n²) O(1) Inserts elements into correct position.
Merge Sort O(n log n) O(n log n) O(n log n) O(n) Divide and merge in sorted order.
Quick Sort O(n log n) O(n log n) O(n²) O(log n) Partitions array using pivot.
Heap Sort O(n log n) O(n log n) O(n log n) O(1) Uses a binary heap to sort.
Counting Sort O(n+k) O(n+k) O(n+k) O(k) Counts frequency of each element.
Radix Sort O(nk) O(nk) O(nk) O(n+k) Sorts by each digit (LSD to MSD).
Bucket Sort O(n+k) O(n+k) O(n²) O(n+k) Distributes elements into buckets.
Tim Sort O(n) O(n log n) O(n log n) O(n) Hybrid of merge and insertion sort.