Ch 4 · Queues — First In, First Out · Data Structures & Algorithms

Topic 4 of 10 in Data Structures & Algorithms — Foundations — 2 lessons.

What Is a Queue?

A queue is the opposite of a stack: the first one in is the first one out — FIFO, just like a line of people. You enqueue at the back and dequeue from the front.

Why Not Just Use a List?

You can dequeue with list.pop(0) — but it is O(n), because every remaining item shifts down a box (remember Card 2.2). A deque is built to be O(1) at both ends. For a real queue, always reach for deque.

All topics in Data Structures & Algorithms Beginner

  1. Thinking Like a Computer Scientist
  2. Arrays & Lists — The Workhorse
  3. Stacks — Last In, First Out
  4. Queues — First In, First Out
  5. Linked Lists — Nodes on a Chain
  6. Searching — Finding the Needle
  7. Sorting — Putting Things in Order
  8. Recursion — Functions That Call Themselves
  9. Hash Tables — Instant Lookups
  10. Mini-Projects & Practice