Solving the Selection Problem with the Rivest-Floyd algorithm
The idea of the Rivest-Floyd selection algorithm is that if we select a subset of an array and find, say, its median, it will be usually pretty close to the original array’s median, and, therefore, a good choice for a pivot. For big arrays, Rivest-Floyd algorithm runs twice as fast as quickselect [1].
Here is my implementation of Rivest-Floyd in Python. I need a slightly different partition function this time:
[1] Floyd, Robert W., and Ronald L. Rivest. “Algorithm 489: the algorithm SELECT—for finding the i th smallest of n elements [M1].” Communications of the ACM 18.3 (1975): 173.