Can someone suggest the fastest way to take the
N minimum elements from a
List, assuming the length of the list is much greater than N. In my case N=10 and the list length is about 8500.
Currently I’m sorting the array and calling
take(10), but it turns out this loop is in the critical path of my program.
And by the way, I’m referring to minimum w.r.t. a measure function.
I’m tempted to copy the list into a mutable Array, and then implement in-place
selectionSort which stops after it has swapped N elements, but I was hoping there was a more elegant way.