◀ dequeue (front)enqueue (back) ▶
Queue is empty — enqueue a value
AlgoPlus//structures / queue
Read the theory

Queue · FIFO

First-In-First-Out — enqueue at the back, dequeue from the front.

Stability
In-Place
Space Complexity
Avg Time
Legend
Enqueue
Dequeue
Front
AI Tutor Workspace
In a nutshell
A queue is a waiting line: you join at the back (enqueue) and are served from the front (dequeue), so whoever arrived first leaves first. That First-In-First-Out order is what makes queues the natural fit for anything served fairly in arrival order — print jobs, tasks waiting for a worker, or requests hitting a server. Both ends are handled in constant time.
Ready
Press play to begin the cinematic walkthrough.
Like a line at a checkout — you join at the back and are served from the front, so the first to arrive is the first to leave.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Queue · FIFO.
Code Simulator
1
class Queue:
2
    def __init__(self):
3
        self.items = []
4
    def enqueue(self, item):
5
        self.items.append(item)  # Enqueue
6
    def dequeue(self):
7
        if not self.is_empty():
8
            return self.items.pop(0)  # Dequeue
Why Python? · Readable first, fast second

Dynamically typed and interpreted — every comparison and swap is dispatched by the interpreter at run time, so tight loops run roughly 10–100× slower than compiled C/C++. Unbeatable for learning the idea with the least code; not what you reach for when the inner loop is the bottleneck.