Finding the first n largest elements in an array

后端 未结 8 443
不思量自难忘°
不思量自难忘° 2020-12-09 04:42

I have got an array containing unique elements. I need to find out the first n largest elements in the array in the least complexity possible. The solution that I could thin

8条回答
  •  隐瞒了意图╮
    2020-12-09 05:20

    Use a modified version of Quick Sort. You do not need to actually sort the whole array. You only need to partition N elements larger than the pivot value. For more information, please read Introduction to Algorithms.

提交回复
热议问题