"Dann Corbit" <DCorbit@xxxxxxxxx> writes: > Instead of sorting, I suggest the quickselect() algorithm, which is > O(n). What for? Common cases have less than half a dozen entries. That is not the place we need to be spending engineering effort --- what we need to worry about is what's the choice algorithm, not implementation details. regards, tom lane