Sorting Algorithms

Algorithm Description Time Best (Ω) Time Average (Θ) Time Worst (O) Space Worst
Heap Sort Uses a binary heap to extract the maximum (or minimum) element and place it in the sorted array. Ω(n log(n)) Θ(n log(n)) O(n log(n)) O(1)
Merge Sort Divides the array, recursively sorts halves, and merges them. Ω(n log(n)) Θ(n log(n)) O(n log(n)) O(n)
Quick Sort Chooses a pivot, partitions the array, and recursively sorts partitions. Ω(n log(n)) Θ(n log(n)) O(n²) O(log(n))
Tree Sort A sorting algorithm that builds a binary search tree from the elements to be sorted, then traverses the tree to retrieve the elements in sorted order. Ω(n log(n)) Θ(n log(n)) O(n²) O(n)
Comb Sort Improves upon bubble sort by using a gap sequence to eliminate turtles, or small values near the end of the list, which slows down the sorting process in bubble sort. Ω(n log(n)) Θ(n²) O(n²) O(1)
Shell Sort Extension of insertion sort that allows the exchange of items that are far apart. It starts by sorting pairs of elements far apart from each other, then progressively reduces the gap between elements to be compared. Ω(n log(n)) Θ((n log(n))²) O(n(log(n))²) O(1)
Cube Sort Operates by recursively dividing the array into sub-cubes, sorting each cube individually, and then merging them back together, offering a balance between time complexity and space complexity. Ω(n) Θ(n log(n)) O(n log(n)) O(n)
Tim Sort A hybrid sorting algorithm derived from merge sort and insertion sort, designed to perform well on real-world data and exploit existing order in the input sequence. Ω(n) Θ(n log(n)) O(n log(n)) O(n)
Bubble Sort Repeatedly compares adjacent elements and swaps them if they are in the wrong order. Ω(n) Θ(n²) O(n²) O(1)
Insertion Sort Builds the final sorted array one element at a time by inserting each element into its position. Ω(n) Θ(n²) O(n²) O(1)
Selection Sort Finds the smallest (or largest) element and places it at the beginning (or end) of the array. Ω(n²) Θ(n²) O(n²) O(1)
Bucket Sort Divides the input array into a number of buckets, each of which is then sorted individually, typically with another sorting algorithm or by recursively applying bucket sort. Ω(n + k) Θ(n + k) O(n²) O(n)
Counting Sort An integer sorting algorithm that works by determining the number of objects having distinct key values and using arithmetic to determine their position in the output array. Ω(n + k) Θ(n + k) O(n + k) O(k)
Radix Sort Sorts based on individual digits or characters, from least to most significant. Ω(nk) Θ(nk) O(nk) O(n + k)