I am currently implementing the Quickselect Algorithm to get the best n elements in a list. The "best" element is in this case the largest.
My problem is the following:
I discovered that this gives poor performance in case of many duplicate elements, because at the end the values that are not sorted will all be the same and at that point the left border will only be incremented by 1 at each iteration regardless of the pivot index.
Is there any way to fix this and abort in this case?