Linear Data Structures

Concept shape

Core
0
1
2
3
4
5
Definition

A queue is a first-in-first-out structure: the oldest item is removed first.

Step 1 / 5
Concept shape
Current lesson

Queues Lab

Linear Data Structures Core

Queues

Welcome to the Queues concept lab. A queue keeps items in arrival order: add at the back, remove from the front. This makes queues natural for fair processing, breadth-first search, task scheduling, and level-order traversal. In JavaScript, avoid teaching Array.shift as the scalable default because removing the front can move the remaining elements. Use an index pointer queue when performance matters. The must know points are: Enqueue at rear. Dequeue at front. BFS depends on queue order. The common operations are: enqueue O(1), dequeue O(1), front O(1), isEmpty O(1). The complexity shape is Core operations O(1). Watch out for these pitfalls: Using slow array shift operations in some languages. Mixing up front and rear. Related algorithms include BFS, Level Order Traversal.

Concept details

A queue keeps items in arrival order: add at the back, remove from the front.

This makes queues natural for fair processing, breadth-first search, task scheduling, and level-order traversal.

In JavaScript, avoid teaching Array.shift as the scalable default because removing the front can move the remaining elements. Use an index pointer queue when performance matters.

Must know

  • Enqueue at rear.
  • Dequeue at front.
  • BFS depends on queue order.

Complexity

Core operations O(1)

Open deeper visual structure lesson
1.0x