LOGBOOK

HELP

Quiz Entry - updated: 2026.12.01

What is a priority queue, and which operations does it offer?

A priority queue stores entries, each a (key, value) pair, and always hands out the entry with the smallest key first. Its core operations are insert(k, v) and removeMin(); min(), size() and isEmpty() complete it.

An ordinary queue serves elements in the order they arrived. A priority queue ignores arrival order: the key of each entry is its priority, and whatever entry has the smallest key is served next, no matter when it came in. The value is the payload that travels with it (a name, a task, an order).

Operation What it does
insert(k, v) adds a new entry (k, v)
removeMin() removes the entry with the smallest key and returns it
min() returns the entry with the smallest key without removing it (like a stack's top() next to pop())
size(), isEmpty() number of entries / whether there are none

Keys must be comparable, either naturally (numbers, strings) or through a comparator supplied to the queue. That total order is all the queue needs to know.

Typical uses are anything where "most urgent first" beats "first come, first served": the best bid in an auction, the best price in a stock exchange order book, a waiting system such as hospital triage or a process scheduler.

Tip: "smallest key = highest priority" is a convention. A queue that serves the largest key first works identically with the comparison reversed.

Go deeper:

  • doc Priority queue — the abstract data type, its implementations and its applications, from Dijkstra to Huffman coding.
  • doc java.util.PriorityQueue — the standard Java heap-based priority queue, with the cost of each method.
  • doc Python heapq — the standard-library min-heap on a plain list, with notes on priority-queue use.

From Quiz: ADS / Priority Queues and Heaps | Updated: Dec 01, 2026