Queue Visualizer

Interactive visualization of queue operations with step-by-step code execution

Queue Structure (FIFO - First In, First Out)

HEAD
← Dequeue (Remove)
First In, First Out
TAIL
Enqueue (Add) →
New elements enter here
50
HEAD
101
152
TAIL
Dequeue removes from HEAD
Enqueue adds to TAIL
Queue Size: 3Head: 5Tail: 15

Queue Operations

Add Element to Queue

Queue Enqueue Operation

1function enqueue(queue, value) {
2  // Add element to the rear of queue
3  queue[queue.rear] = value;
4  
5  // Move rear pointer forward
6  queue.rear = queue.rear + 1;
7  
8  // Increment queue size
9  queue.size++;
10  
11  return queue;
12}
Step 1 of 4

Add the new element to the rear of the queue

About Queues

Understanding the fundamentals, properties, and complexity analysis of queue data structures

What is a Queue?

A queue is a linear data structure that follows the First In, First Out (FIFO) principle. Elements are added at the rear (enqueue) and removed from the front (dequeue). Think of it like a line at a store - the first person in line is the first to be served.

Advantages

  • Fair ordering - first come, first served
  • Constant time O(1) enqueue and dequeue
  • Simple and predictable behavior

Disadvantages

  • Limited access - only front and rear
  • No random access to elements
  • Memory overhead in array implementation

Properties

Type:Linear FIFO
Access:Front & Rear
Enqueue:O(1)
Dequeue:O(1)
Peek:O(1)
Search:O(n)

Common Use Cases

Task Scheduling

Process tasks in order of arrival

Breadth-First Search

Explore nodes level by level

Print Queue

Handle print jobs in order

Buffer for Data Streams

Handle incoming data streams

Call Center Systems

Manage customer service queues

Time Complexity

Core Operations

Enqueue (add to rear)O(1)
Dequeue (remove from front)O(1)
Peek (view front)O(1)

Other Operations

Search elementO(n)
Check if emptyO(1)
Get sizeO(1)

Space Complexity

Total spaceO(n)
Auxiliary spaceO(1)