How fast can we sort? less
Depends on the computational model of what you can do with the elements.dom
Comparison sorting model:ui
Only use comparisons to determine the relative order of elements.blog
Decision-tree model comparison sorts:ci
--one tree for each nelement
--view algorithm as splitting whenever it make a comparisonit
--tree lists comparisons along all possible instruction tracesio
--running time (# comparisons) = length of pathast
--worst-case run time = height of treebfc
--the # of leaves is n factorial
Corollary: Merge sort and heapsort are asymptotically optimal comparison sorts.
Randomized quick sort is too, in expectation.
Theoretically Radix sort is very beautiful, but it not very good on cache, so in practice it is not that fast unless the number of sorting is really small. Something like quick sort can do better.