I have a list containing n double values and I k The lowest list in the list Which algorithms would you recommend? At this time I use Quicksort to sort the entire list, and then for the first time I K element sorted list I hope that should be very fast algorithm. Thank you for your help! You can use to find the lowest element, and then repeat it and Return it back and all the elements which are less, this is If the list can be duplicated (to ensure that you do not need more elements, which you do not need), more work is done. Another option maximum size When you do - the smallest elements in the heap are
This solution is o (n) the selection algorithm is implemented in C ++
K , and repeat the elements to maintain the pile to catch everyone, the minimum element.
for each element x: if (heap.size () & lt; k): heap.add (x) and if x & lt; Heap.max (): heap.pop () heap.add (x)
this solution o (nlogk )
Comments
Post a Comment