Unit content
Priority queues
A priority queue stores elements together with priorities and supports access to the element with highest or lowest priority.
Typical operations are:
- insert an element;
- inspect the minimum or maximum priority element;
- remove that element;
- sometimes change an existing priority.
A priority queue is an abstract data type: it specifies useful operations without requiring one particular representation.
An unsorted collection can make insertion cheap but removal of the best element expensive. A sorted representation makes the opposite trade-off. Heap structures provide a useful balance, supporting insertion and best-element removal efficiently.
Priority queues appear in scheduling, shortest-path algorithms, event simulation and any process that repeatedly chooses the currently most important item.