Solution:
The Heap has n elements,
n n-1 n-2 .....k....3 2 1
^^^^^^^^^^
The Kth largest element happens somewhere in this range,
because it is a heap, and every parent >= child.
Possible solution, copy the last k elements to the temporary structure,
and build a heap which will take O(k) time and compare the root with the number x.
No comments:
Post a Comment