Queues in Data Structures
A practical guide to the queue data structure — how FIFO differs from a stack, the different flavors of queues, real-world uses like task scheduling and BFS, and a working implementation.

If a stack is a pile of plates, a queue is a line at a ticket counter — whoever got in line first gets served first. That single difference in ordering changes what a queue is good for, and it shows up in more systems than most people expect.
The Core Idea: First In, First Out
A queue follows the opposite rule from a stack: the first item added is the first item removed — FIFO, for short.
New items join at the back of the queue. Items leave from the front. Nobody cuts the line, and nobody at the front gets skipped.
The Core Operations
- Enqueue — add an item to the back
- Dequeue — remove and return the item at the front
- Front / Peek — look at the front item without removing it
- isEmpty — check whether the queue has anything in it
Why Not Just Use a Plain List?
Removing from the front of a plain array or Python list is slow — every remaining element has to shift over by one position, making it an O(n) operation. Real queue implementations avoid this with either a linked list (removing from the head is O(1)) or a circular buffer (a fixed-size array that wraps around instead of shifting).
That's why, in Python, you'd reach for collections.deque rather than a plain list when you need real queue behavior — it's built for O(1) operations at both ends.
The Different Flavors of Queues
- Simple Queue — the basic FIFO version described above.
- Circular Queue — the array wraps around instead of leaving wasted space at the front after dequeues, making it memory-efficient for fixed-capacity use cases like buffering.
- Priority Queue — items don't leave strictly in arrival order; instead, the item with the highest priority leaves first, regardless of when it joined. Usually implemented with a heap.
- Deque (Double-Ended Queue) — items can be added or removed from either end, which makes it flexible enough to act as a stack, a queue, or both.
A Simple Implementation (Python)
pythonfrom collections import deque class Queue: def __init__(self): self._items = deque() def enqueue(self, item): self._items.append(item) def dequeue(self): if self.is_empty(): raise IndexError("dequeue from an empty queue") return self._items.popleft() def front(self): if self.is_empty(): raise IndexError("front from an empty queue") return self._items[0] def is_empty(self): return len(self._items) == 0 q = Queue() q.enqueue("first") q.enqueue("second") q.enqueue("third") print(q.dequeue()) # first print(q.front()) # second
Where Queues Show Up in Real Systems
- Breadth-First Search (BFS). Whenever an algorithm needs to explore "everything one step away, then everything two steps away," it's using a queue — this is how shortest-path searches on graphs and grids work.
- Task and job scheduling. Print jobs, background workers, and CPU task scheduling are all queue-driven so that requests are handled in the order they arrive.
- Handling requests at scale. Web servers and message brokers (like a request queue in front of an API) use queues to smooth out bursts of traffic instead of dropping requests.
- Data streaming and buffering. Video streaming and audio processing pipelines use queues (often circular ones) to hold data momentarily as it's produced and consumed at different rates.
- Call center / customer support systems. The literal real-world use case a queue is named after — callers are served in the order they called in, unless a priority queue is layered on top for urgent cases.
Stack vs. Queue, in One Line
A stack answers "what did I just do?" A queue answers "what's been waiting the longest?" Picking the right one comes down to which question your problem is actually asking.
The Takeaway
A queue is a small, disciplined rule — first in, first out — but that rule is exactly what makes systems fair, predictable, and orderly under load. Any time you see "process things in the order they arrived," there's very likely a queue running underneath it.


