Kth largest element in a max-heap

后端 未结 4 741
清酒与你
清酒与你 2020-12-25 15:11

I\'m trying to come up with something to solve the following:

Given a max-heap represented as an array, return the kth largest element without modifyi

4条回答
  •  自闭症患者
    2020-12-25 16:10

    To the best of my knowledge, there's no easy algorithm for solving this problem. The best algorithm I know of is due to Frederickson and it isn't easy. You can check out the paper here, but it might be behind a paywall. It runs in time O(k) and this is claimed to be the best possible time, so I suspect that a log-time solution doesn't exist.

    If I find a better algorithm than this, I'll be sure to let you know.

    Hope this helps!

提交回复
热议问题