Repaso
Español
Algorithms & DSCoreALG-43

A queue is…

Options

  1. Last in, first out (LIFO): the newest leaves first
  2. First in, first out (FIFO): the oldest leaves first (Correct option)
  3. Random order, with no rule for what is removed
  4. 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).

Key terms

Practice this question in Repaso