| | | | | next -> |

Summary


SortWC RuntimeRunspaceStabilityGenericComments
Selection SortΘ(n2)in placenoForward Always n(n+1)/2 comps
Insertion SortΘ(n2)in placeyesBidirectional Improves to linear as input approaches sorted
HeapsortΘ(n log n)in placenoRandom Access Widely spaced Swaps may cause paging
Quicksort Θ(n2)
+ Θ(n)noSmart Bidirectional AC = Θ(n log n)
Merge Sort (array)Θ(n log n)+ Θ(n) yesRandom Access Extra space costly in time
Merge Sort (list)Θ(n log n)in place yesMember 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.

| next -> | Top of Page | 8. Sorting Algorithms - 16 of 16