Skip to interview prep
Apexed

144. How does a priority queue differ from an ordinary FIFO queue?

EasyQueues

Technical
Show model answer

A FIFO queue removes items in arrival order, and with a linked list or circular array both enqueue and dequeue are O(1). A priority queue removes the item with the highest priority (smallest or largest key) regardless of arrival order; a binary heap gives O(log n) insert and remove, and O(1) peek.

Use FIFO for fairness and ordering: buffers, BFS, request handling. Use a priority queue when urgency or cost decides the order: Dijkstra, event simulation, task scheduling, top-k. A plain binary heap is not stable, so attach an arrival counter as a tiebreaker if equal priorities must stay in FIFO order.

How does a priority queue differ from an ordinary FIFO queue — Data structures & algorithms interview question — Apexed