Queue Visualization & Animation
First-In-First-Out structure with O(1) enqueue and dequeue; backbone of BFS and task scheduling.
## What is it?
A Queue is a First-In-First-Out (FIFO) data structure. Elements are added (enqueued) at the rear and removed (dequeued) from the front. Think of a queue of people waiting in line.
## How it works
**Core operations (all O(1) with proper implementation):**
- **enqueue(x)** — add `x` to the rear
- **dequeue()** — remove and return the front element
- **peek() / front()** — return the front element without removing it
- **isEmpty()** — check if the queue has no elements
**Implementations:**
- Circular array (avoids O(n) shifting on dequeue)
- Linked list (push at tail, pop at head)
- Two stacks (amortized O(1))
## When to use
- Breadth-First Search (BFS)
- Task scheduling / print spooling
- Sliding window maximum (with a deque)
- Producer-consumer problems
## Key Points
- FIFO — the first element added is the first removed
- A Deque (double-ended queue) supports push/pop at both ends
- Priority Queue orders elements by priority, not insertion order
Category: data-structure
Difficulty: beginner
Time Complexity: O(1) enqueue/dequeue
Space Complexity: O(n)
View Queue Visualization