Summary
Sort | WC Runtime | Runspace | Stability | Generic | Comments |
Selection Sort | Θ(n2) | in
place | no | Forward |
Always n(n+1)/2 comps |
Insertion Sort | Θ(n2) | in
place | yes | Bidirectional |
Improves to linear as input approaches sorted |
Heapsort | Θ(n log n) | in place | no | Random Access |
Widely spaced Swaps may cause paging |
Quicksort |
Θ(n2)
|
+ Θ(n) | no | Smart Bidirectional |
AC = Θ(n log n) |
Merge Sort (array) | Θ(n log n) | + Θ(n) |
yes | Random Access |
Extra space costly in time |
Merge Sort (list) | Θ(n log n) | in place |
yes | Member Function |
in-place! But Lists are slow. |
Counting Sort | Θ(n + k) | +
Θ(k) | yes |
|
Function Object argument |
Radix Sort | Θ(d(n + k)) | + Θ(k) | yes | |
|
|
Bit Sort | Θ(nb) |
+
Θ(n) | yes |
|
Use Bit function object in counting sort |
Byte Sort | Θ(nB) | +
Θ(n) | yes |
|
Use Byte function object in counting sort |
n = number of items to be sorted, k = upper bound of size of
integers to be sorted, d = loop length (radix sort), b = number
of bits in number type (bit_sort), B = number of bytes (byte_sort).
WC = worst case, AC = average case
For additional informative and entertaining
discussion of sorts, see the entry in Wikipedia.
|