Beruflich Dokumente
Kultur Dokumente
In this table, n is the number of records to be sorted. The columns "Average" and "Worst" give the time complexity in each case, under the assumption that the length of each key is constant, and that therefore all comparisons, swaps, and other needed operations can proceed in constant time. "Memory" denotes the amount of auxiliary storage needed beyond that used by the list itself, under the same assumption. These are all comparison sorts. The run time and the memory of algorithms could be measured using various notations like theta, sigma, Big-O, small-o, etc. The memory and the run times below are applicable for all the 5 notations.
Comparison sorts
Name
Best
Average
Worst
Memor y
Stable
Method
Other notes
Quicksort
Depends
Quicksort can be done in place with O(log(n)) stack space, but the sort is unstable[citation Partitionin needed]. Nave variants use g an O(n) space array to store the partition. An O(n) space implementation can be stable[citation needed].
Merge sort
Depend s
Yes
Merging
Heapsort
No
Selection
Average case is Insertion sort Yes , Insertion also whered is the number of inversions
Introsort
No
Selection sort
Its stability depends on the implementation. Used Depends[3 Selection to sort this table in Safari ]. or other Webkit web browser [4].
Timsort
Yes
Insertion comparisons when the & data is already sorted or Merging reverse sorted.
Shell sort
No
Insertion
Bubble sort
Yes
Yes
Cycle sort
No
Library sort
Yes
Insertion
Patience sorting
No
Finds all the longest Insertion increasing & subsequences within Selection O(n log n)
Smoothsort
No
An adaptive sort comparisons when the Selection data is already sorted, and 0 swaps.
Strand sort
Yes
Selection
Tournament sort
Selection
Cocktail sort
Yes
Exchangin g
Comb sort
No
Gnome sort
Yes
Yes
Implemented in Standard Template Library (STL): [5]; can be Merging implemented as a stable sort based on stable inplace merging: [6]
Bogosort
No
Luck
The following table describes integer sorting algorithms and other sorting algorithms that are not comparison sorts. As such, they are not limited by a lower bound. Complexities below are in terms of n, the number of
items to be sorted, k, the size of each key, and d, the digit size used by the implementation. Many of them are based on the assumption that the key size is large enough that all entries have unique key values, and hence that n << 2 , where << means "much less than."
k
Non-comparison sorts
Name
Best
Average
Worst
Memory
Stable
n << 2k
Notes
Pigeonhole sort
Yes
Yes
Yes
No
r is the range of numbers to be Counting sort Yes Yes sorted. If r = RT = then Avg
[2]
Yes
No
[3][2]
Yes
No
Stable version uses an external array of size n to hold all of the bins
No
No
Spreadsort
No
No
Asymptotics are based on the 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 Averag t e
Worst
Memory
Stabl Compariso e n
Other notes
Bead sort
N/A
N/A
N/A
No
No
Yes
Yes
Polling
This A linear-time, analog algorithm for sorting a sequence of items, requiring O(n) stack space, and the sort is stable. This requires a parallel processor. Spaghetti sort#Analysis
Sorting network s