Loading section...
Queue Fundamentals: The FIFO Discipline
Concepts: pyQueueFundamentals, pyFIFO, pyBFS
A queue is a line. First in, first out. The person who arrived first gets served first. In Python, the right tool is collections.deque, not a list. Here is why this matters in an interview: list.pop(0) is O(n) because Python has to shift every element left. deque.popleft() is O(1) because it is a doubly-linked list under the hood. If you use list as a queue in a coding interview at Google, the interviewer will catch it. Use deque. Every time. FIFO Intuition and Why It Matters FIFO guarantees fairness and ordering. The first element enqueued is the first processed. This is the right behavior for: BFS graph traversal (process nodes level by level), job schedulers (tasks run in submission order), message queues (events processed in arrival order), and pipeline task scheduling (upstream tasks