← Queues · guided lesson

Queues & Deques

1 / 18 · story

the story

Queue (FIFO)

Every tool here exists because something was too slow or broke without it. Here is what.

1909–1917 · Agner Krarup Erlang, Copenhagen Telephone Company

Nobody invented "first come, first served" — waiting lines are older than computers, and the FIFO queue in code has no single inventor. What has a clear start is the maths of queues. In 1909 Erlang, an engineer at the Copenhagen Telephone Company, showed that calls made at random follow a Poisson distribution. His 1917 paper gave formulas for lost calls and waiting time, and telephone companies in many countries adopted them. That field, queueing theory, is still how engineers size server pools, call centres and network buffers.

the problem it solved

How many lines a telephone exchange needs so that calls rarely wait or get lost — sizing any system that serves requests in arrival order.

why it matters: without it

Bursts of work would be dropped or served in random order — no fairness for print jobs or bookings — and BFS would stop finding shortest paths.

sources: MacTutor History of Mathematics — Agner Krarup Erlang (University of St Andrews) ↗

also in this chapter: Circular buffer (ring buffer) · Deque and Java's ArrayDeque · Monotonic deque · Queue from two stacks (amortized O(1))