Selection algorithm: Difference between revisions

Content deleted Content added
source matlab; let's not include user-supplied unofficial routines like the Perl ones
Line 52:
 
== 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}}