Indexed Priority Queues and Decrease-Key
Maintain a key-to-position map alongside a heap and use it to repair an entry after a priority change.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Track identities through swaps
An ordinary binary min-heap locates the minimum at its root. Finding an arbitrary item by identity might require a full scan. An indexed heap stores both the heap array and an inverse map from item identifier to array index. Every heap swap updates the two affected map entries. After lowering a key, look up its location and sift up, because the only possible new order violation involves an ancestor. Raising a key instead requires a downward repair.
Distinguish replacement from duplicate entries
Suppose the queue holds tentative distance \(7\) for a vertex and discovers distance \(4\). A decrease-key changes the stored key in \(O(\log n)\) time. An alternative implementation pushes a fresh pair and discards stale pairs when they reach the root, comparing against the distance table. This can increase queue size and changes memory bounds. Both approaches can implement Dijkstra’s algorithm. Bottom-up heap construction is useful when all initial priorities are available at once.[1]