Retrieve the two highest item from a list containing 100,000 integers

后端 未结 15 807
心在旅途
心在旅途 2020-12-13 17:55

How can retrieve the two highest item from a list containing 100,000 integers without having to sort the entire list first?

15条回答
  •  醉酒成梦
    2020-12-13 18:20

    The second highest item is a fairly simple case, but for the kth highest item what you want is a selection algorithm. That page is pretty thorough so it's probably best just to read that.

提交回复
热议问题