Skip to content
Advertisement

Tag: heap

How can I implement decrease-key functionality in Python’s heapq?

I know it is possible to realize decrease-key functionality in O(log n) but I don’t know how? Answer To implement “decrease-key” effectively, you’d need to access the functionality “decrement this element AND swap this element with a child until heap condition is restore”. In heapq.py, that’s called _siftdown (and similarly _siftup for INcrementing). So the good news is that the

Advertisement