Chapter 4. Heaping It On
Instead of just storing a collection of values, what if you stored a collection of entries, where each entry has a value and an associated priority represented as a number? Given two entries, the one whose priority is higher is more important than the other. The challenge this time is to make it possible to insert new (value, priority) entries into a collection and be able to remove and return the value for the entry with highest priority from the collection.
This behavior defines a priority queue—a data type that efficiently
supports enqueue(value, priority) and dequeue(), which removes the value
with highest priority. The priority queue is different from the symbol
table discussed in the previous chapter because you do not need to know
the priority in advance when requesting to remove the value ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access