Removing a node from the middle of the heap can be done in O (log n) if we can find the element on the heap in constant time. Suppose the cube node contains id as a field. Now, if we provide an identifier, how can we remove the node at O (lg n) time?
One solution could be that we can have a location address in each node, where we store the node index on the heap. This array will be ordered using node ids. However, this requires an additional array. Is there any other good method to achieve the same.
PS: I encountered this problem when implementing the Shortist Path algorithm from Djikstra.
source
share