What would be the best solution to find top N (say 10) elements in an unordered list (of say 100).
The solution which came in my head was to 1. sort it using quick s
How about delegating everything to Java ;)
function findTopN(Array list, int n)
{
Set sortedSet = new TreeSet<>(Comparators.naturalOrder());
// add all elements from list to sortedSet
// return the first n from sortedSet
}
I am not trying to say that this is the best way. I still think Yin Zhu's method of finding the kth largest element is the best answer.