Sorting AlgorithmType of Algorithm Main Characteristics Best Time Complexity
Average Time Complexity
Worst Time Complexity
Space Comp
Selection Sort Comparison-Based Selects min element and swaps O(n^2) O(n^2) O(n^2) O(1)
Bubble Sort Comparison-Based Swaps adjacent elements O(n) O(n^2) O(n^2) O(1)
Insertion Sort Comparison-Based Builds sorted array one by one O(n) O(n^2) O(n^2) O(1)
Merge Sort Divide and Conquer Recursively divides array O(n log n) O(n log n) O(n log n) O(n)
Quick Sort Divide and Conquer Partitions array around a pivot O(n log n) O(n log n) O(n^2) O(log n)
Heap Sort Comparison-Based Uses binary heap data structure O(n log n) O(n log n) O(n log n) O(1)
Counting Sort Non-Comparative Counts occurrences of elements O(n + k) O(n + k) O(n + k) O(n + k)
Radix Sort Non-Comparative Sorts based on digit places O(nk) O(nk) O(nk) O(n + k)
Bucket Sort Non-Comparative Distributes elements into buckets O(n + k) O(n + k) O(n^2) O(n + k)
Legend:
- n: Number of elements in the array
- k: Range of input (for Counting, Radix, and Bucket Sort)