'report the smallest k-th elements in a min-heap in O(klogk)
I saw online that this is the correct code:
Initialise the min-heap with correct values. Create a priority queue and insert the root node of the min-heap. Write a loop that iterates k - 1 times. Pop the least element from the queue. Add the left and right nodes of the above node into the priority queue. The greatest element in priority queue is the k-th greatest element now. Return it.
But I am not sure about the complexity of removing an element from the priority queue. Also, find the left node and right node of a min-heap should takes O(logn). Thank you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
