What is an adaptable priority queue, and which operations does it add?
An adaptable priority queue lets you change or remove an entry after it was inserted, not only the minimum. insert returns the entry e as a handle, and remove(e), replaceKey(e, k) and replaceValue(e, v) act on that handle; the queue keeps its internal order correct after each change.
| Operation | Effect | Returns |
|---|---|---|
insert(k, v) |
inserts a new entry e = (k, v) | the entry e |
remove(e) |
removes entry e, wherever it is | e |
replaceKey(e, k) |
gives e the new key k and reorders if needed | the old key |
replaceValue(e, v) |
gives e the new value v | the old value |
Why is this needed? A plain priority queue only lets you touch the minimum. A seller on an exchange who wants to lower an offer would have to call removeMin() until their own entry comes out, keep all the others in a side list, insert the changed offer and then re-insert everything else. That works, but it is clumsy and slow, which is exactly why the adaptable interface exists. Real priorities change while an item is waiting: a standby passenger is upgraded, a bid is withdrawn, a patient's condition worsens, an order is cancelled. Without these operations you would have to empty the queue to find the entry. Graph algorithms such as Dijkstra's shortest path rely on exactly this: lowering a node's tentative distance is a replaceKey on an entry that is already in the queue.
The entry returned by insert is what makes it possible (a plain priority queue's insert need not return anything). It is a handle the caller keeps, so later operations can name the entry directly rather than searching for it by key.
Go deeper:
Dijkstra's algorithm — the classic user of a priority queue whose keys must decrease after insertion.
Binary heap: decrease or increase key — the heap side of replaceKey, and why it needs the element's position.