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
- Thinking Like a Computer Scientist
- Arrays & Lists — The Workhorse
- Stacks — Last In, First Out
- Queues — First In, First Out
- Linked Lists — Nodes on a Chain
- Searching — Finding the Needle
- Sorting — Putting Things in Order
- Recursion — Functions That Call Themselves
- Hash Tables — Instant Lookups
- Mini-Projects & Practice