The Floyd-Rivest algorithm is a divide and conquer algorithm, sharing many similarities with quickselect. It uses sampling to help partition the list into three sets. It then recursively selects the kth smallest element from the appropriate set.
The general steps are:
By using |S| = Θ(n2/3 log1/3 n), we can get n + min(k, n − k) + O(n2/3 log1/3 n) expected comparisons. We can get n + min(k, n − k) + O(n1/2 log1/2 n) expected comparisons by starting with a small S and repeatedly updating u and v to keep the size of B small enough (O(n1/2 log1/2 n) at Θ(n) processed elements) without unacceptable risk of the desired element being outside of B.
The following pseudocode rearranges the elements between left and right, such that for some value k, where left ≤ k ≤ right, the kth element in the list will contain the (k − left + 1)th smallest value, with the ith element being less than or equal to the kth for all left ≤ i ≤ k and the jth element being larger or equal to for k ≤ j ≤ right:
Floyd, Robert W.; Rivest, Ronald L. (1975). "Algorithm 489: The Algorithm SELECT—for Finding the ith Smallest of n elements" (PDF). Comm. ACM. 18 (3): 173. CiteSeerX 10.1.1.309.7108. doi:10.1145/360680.360694. S2CID 122069429. /wiki/Robert_W._Floyd ↩
Two papers on the selection problem: Time Bounds for Selection and Expected Time Bounds for Selection (PDF) (Technical report). Stanford Computer Science Technical Reports and Technical Notes. April 1973. CS-TR-73-349. http://i.stanford.edu/pub/cstr/reports/cs/tr/73/349/CS-TR-73-349.pdf ↩