Comparison of Algorithms: Name Best Average Worst Memor y Stable Method Other Notes
Comparison of Algorithms: Name Best Average Worst Memor y Stable Method Other Notes
Name Best Comparison sorts Memor Average Worst Stable Method Other notes y Quicksort is usually done in place with O(log(n)) stack space.
[citation needed]
Quicksort
Most implementati ons are unstable, as Depen Partitioni stable inds ng place partitioning is more complex. Nave variants use an O(n) space array to store the partition.
[citation needed]
Merge sort
Implemented in Standard Template Library (STL): [3]; can be Yes Merging implemented as a stable sort based on stable inplace merging: [4] No Selection O(n + d), where d is the Yes Insertion number of inversions No Partitioni Used in SGI
Name
Best
Selection sort
Timsort
Shell sort
Comparison sorts Memor Average Worst Stable Method Other notes y STL ng & implementati Selection ons Stable with O(n) extra space, for example using lists No Selection [5]. Used to sort this table in Safari or other Webkit web browser [6]. comparison s when the Insertion data is Yes & already Merging sorted or reverse sorted. Depends on gap sequence; No Insertion or best known is Exchangi Tiny code ng size When using a selfYes Insertion balancing binary search tree In-place with theoretically No Insertion optimal number of writes Yes Insertion No Insertion Finds all the & longest Selection increasing subsequences within O(n Yes
Bubble sort
Cycle sort
Name
Best
Smoothsort
Strand sort Tournament sort Cocktail sort Comb sort Gnome sort
Comparison sorts Memor Average Worst Stable Method Other notes y log n) An adaptive sort comparisons No Selection when the data is already sorted, and 0 swaps. Yes Selection Selection Exchangi ng Exchangi Small code No ng size Exchangi Tiny code Yes ng size Randomly permute the No Luck array and check if sorted. Remarkably inefficient No Selection sorting algorithm [7] Yes
Bogosort
Slowsort
Non-comparison sorts Name Best Average Worst Memory n Stable << 2k Yes Yes Yes No Assumes uniform distribution of elements from the Notes
Non-comparison sorts Name Best Average Worst Memory n Stable << 2k Notes domain in the array.
[2]
Yes
No
[3][2]
Yes
No
Spreadsort
No
Stable version uses an external array of No size n to hold all of the bins In-Place. k / d No recursion levels, 2d for count array Asymptotics are based on the No assumption that n << 2k, but the algorithm does not require this.
The following table describes some sorting algorithms that are impractical for real-life use due to extremely poor performance or a requirement for specialized hardware. Name Bes Avera Wor Stab Comparis Memory t ge st le on N/A No No Yes Other notes Requires specialized hardware Count is number of flips.
Bead N/A N/A sort Simple pancak e sort Spaghe tti (Poll) sort
Yes
This A linear-time, analog algorithm for sorting a sequence of items, Polling requiring O(n) stack space, and the sort is stable. This requires parallel processors. Spaghetti sort#Analysis
Name
Sorting networ ks
Additionally, theoretical computer scientists have detailed other sorting algorithms that provide better than
Han's algorithm, a deterministic algorithm for sorting keys from a domain of finite size, taking time and space.[4] Thorup's algorithm, a randomized algorithm for sorting keys from a domain of finite size, taking time and space.[5] expected time and