A queue is…
Options
- Last in, first out (LIFO): the newest leaves first
- First in, first out (FIFO): the oldest leaves first (Correct option)
- Random order, with no rule for what is removed
- A structure that stores only numbers, not text
Answer
First in, first out (FIFO): the first item added is the first removed
Why
Like a line at the supermarket: people join at the back and are served from the front.
In Python use collections.deque: append() adds at the back, popleft() removes from the front, both O(1).
Uses: task queues, BFS, buffering messages.
Remember
Queue = FIFO (supermarket line).