{ } LinearCore interactive

Queue

First-In-First-Out. Enqueue, dequeue.

queue
size 3
← front (dequeue)back (enqueue) →
3
8
15

FIFO — elements leave in the exact order they arrived.

How it works

A queue is FIFO: elements leave in the order they arrived, like a line at a checkout. Implemented with a ring buffer or linked list, both ends are O(1). It powers schedulers, BFS, and every producer/consumer pipeline.

Mental models

  • Two pointers — head and tail — move forward; the middle never shifts.
  • A circular buffer reuses freed slots so memory stays bounded.

Complexity

Enqueue
O(1)
Dequeue
O(1)
Peek
O(1)
Search
O(n)
Space
O(n)

Reach for it when

  • BFS traversal
  • Task & job scheduling
  • Streaming / buffering