Comparison Sorts Name Best Average Worst Memory Stable Method Other Notes Quicksort Is Usually Done in Place with O(Log N) Stack Space
Total Page:16
File Type:pdf, Size:1020Kb
Comparison sorts Name Best Average Worst Memory Stable Method Other notes Quicksort is usually done in place with O(log n) stack space. Most implementations on typical in- are unstable, as stable average, worst place sort in-place partitioning is case is ; is not more complex. Naïve Quicksort Sedgewick stable; Partitioning variants use an O(n) variation is stable space array to store the worst versions partition. Quicksort case exist variant using three-way (fat) partitioning takes O(n) comparisons when sorting an array of equal keys. Highly parallelizable (up to O(log n) using the Three Hungarian's Algorithmor, more Merge sort worst case Yes Merging practically, Cole's parallel merge sort) for processing large amounts of data. Can be implemented as In-place merge sort — — Yes Merging a stable sort based on stable in-place merging. Heapsort No Selection O(n + d) where d is the Insertion sort Yes Insertion number of inversions. Introsort No Partitioning Used in several STL Comparison sorts Name Best Average Worst Memory Stable Method Other notes & Selection implementations. Stable with O(n) extra Selection sort No Selection space, for example using lists. Makes n comparisons Insertion & Timsort Yes when the data is already Merging sorted or reverse sorted. Makes n comparisons Cubesort Yes Insertion when the data is already sorted or reverse sorted. Small code size, no use Depends on gap of call stack, reasonably sequence; fast, useful where Shell sort or best known is No Insertion memory is at a premium such as embedded and older mainframe applications. Bubble sort Yes Exchanging Tiny code size. When using a self- Binary tree sort Yes Insertion balancing binary search tree. In-place with Cycle sort — No Insertion theoretically optimal number of writes. Library sort — Yes Insertion Finds all the longest Insertion & Patience sorting — No increasing subsequences Selection in O(n log n). Smoothsort No Selection An adaptive sort: Comparison sorts Name Best Average Worst Memory Stable Method Other notes comparisons when the data is already sorted, and 0 swaps. Strand sort Yes Selection [4] Tournament sort — ? Selection Cocktail sort Yes Exchanging Comb sort No Exchanging Small code size. Gnome sort Yes Exchanging Tiny code size. No exchanges are performed. Performance Can be is independent of data made size. The constant 'k' is In place for stable by proportional to the linked lists. Distribution UnShuffle Sort appending entropy in the input. K N*sizeof(link) and Merge the input = 1 for ordered or for array. order to the ordered by reversed key. input so runtime is equivalent to checking the order O(N). Franceschini's method — Yes ? Combine a block-based Insertion & O(n) in-place merge Block sort Yes Merging algorithm with a bottom-up merge sort. Random Bogosort No shuffling .