<strong>An</strong> <strong>efficient</strong> <strong>implementation</strong> <strong>of</strong> <strong>Blum</strong>, <strong>Floyd</strong>, <strong>Pratt</strong>, <strong>Rivest</strong>, and Tarjan’s worst-case linear selection algorithm Contents Derrick Coetzee, webmaster@moonflare.com January 22, 2004 1 Introduction 1 2 The Average-Case Linear, Fast Algorithm 3 3 The Worst-Case Linear Algorithm 5 4 The Key: A Fast Median-<strong>of</strong>-5 Function 7 5 The partition function 9 6 Driver and Benchmarking 10 7 Conclusions and Possible Improvements 13 8 Indexes 13 8.1 Code Chunks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 8.2 Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1 Introduction In 1973, Manuel <strong>Blum</strong>, Robert W. <strong>Floyd</strong>, Vaughan <strong>Pratt</strong>, Ronald L. <strong>Rivest</strong>, and Robert E. Tarjan wrote a paper entitled Time bounds for selection which explored the problem <strong>of</strong> selecting the kth smallest element in an array, and demonstrated an explicit algorithm for solving it in worst-case O(n) time, using only comparisons. This algorithm has been republished in many other works, and this <strong>implementation</strong> is based on the description given in Cormen, Leiserson, <strong>Rivest</strong>, and Stein’s important textbook Introduction to Algorithms. In practice, the algorithm is typically not used, nor should be in its naïve form, because there is a much simpler algorithm, a close relative <strong>of</strong> quicksort, 1