Content deleted Content added
erickson |
exact #s |
||
Line 51:
For deterministic algorithms, it has been shown that selecting the <math>k</math> element requires <math>\bigl(1+H(k/n)\bigr)n+\Omega(\sqrt n)</math> comparisons, where <math display=block>H(x)=x\log_2\frac1x + (1-x)\log_2\frac1{1-x}</math> is the [[binary entropy function]].{{r|benjoh}} The special case of median-finding has a slightly larger lower bound on the number of comparisons, at least <math>(2+\varepsilon)n</math>, for <math>\varepsilon\approx 2^{-80}</math>.{{r|dz01}}
== Exact numbers of comparisons ==
Knuth supplies the following triangle of numbers summarizing known pairs of <math>n</math> and <math>k</math> for which the exact number of comparisons needed by an optimal selection algorithm is known. The <math>n</math>th row of the triangle (starting with <math>n=1</math> in the top row) gives the numbers of comparisons for inputs of <math>n</math> values, and the <math>k</math>th number within each row gives the number of comparisons needed to select the <math>k</math>th smallest value from an input of that size. The rows are symmetric because selecting the <math>k</math>th smallest requires exactly the same number of comparisons, in the worst case, as selecting the <math>k</math>th largest.{{r|knuth}}
{{center|0}}
{{center|1 1}}
{{center|2 3 2}}
{{center|3 4 4 3}}
{{center|4 6 6 6 4}}
{{center|5 7 8 8 7 5}}
{{center|6 8 10 10 10 8 6}}
{{center|7 9 11 12 12 11 9 7}}
{{center|8 11 12 14 14 14 12 11 8}}
{{center|9 12 14 15 16 16 15 14 12 9}}
== Language support ==
|