Priority Queue
Pronunciationpry-OR-ih-tee KYOO
Definition
A priority queue is a collection where each item has a priority, and the next item you take out is always the one with the highest priority (or lowest value), not the oldest one.
Where you hear it
In schedulers, shortest-path algorithms (Dijkstra), job systems and Python's heapq.
Examples
Urgent jobs jump ahead of normal ones in the priority queue.
heapq.heappopreturns the smallest item.The support queue serves the urgent tickets first, then the rest in arrival order.
Common mistake
Using a sorted list and re-sorting after every insert. A heap-based priority queue is far faster.
Don't confuse with
A normal queue (FIFO), which serves items strictly in arrival order.
Say it at work
- In a meeting or chat
Put the tasks in a priority queue.
- In an email or ticket
Break ties by insertion order.
Keep exploring
More in Programming Fundamentals