Queues: First In, First Out · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

The line with no overtaking

Computing · Algorithms & Data Structures · ages 16-18
Name ______________________   Date ____________
  1. You enqueue 4, enqueue 7, dequeue, enqueue 9. What is at the front?

    • 9
    • 4
    • 7
  2. What is the queue rule?

    • Last in, first out
    • First in, first out
    • Largest value leaves first
  3. Same four values through a stack and a queue: how do the outputs compare?

    • Identical in both
    • Reversed in the stack, arrival order in the queue
    • Random in both
  4. The front print job jams. What happens and what fixes it?

    • The line reorders itself automatically
    • Everything behind waits; cancel or restart the front job and the line flows in order
    • Later jobs jump ahead of the jam
  5. Why does a print spooler keep jobs in a queue?

    • Printers print fastest in reverse
    • One printer serves many in order
    • Queues use less paper
  6. Removing from position zero of a Python list is the fastest way to run a huge queue.

    Circle one:   True   False

  7. A student runs editor undo on a queue and oldest edits vanish last. What is the error?

    • Undo needs newest first, which is stack order, not queue order
    • Queues cannot store edits
    • Undo needs no structure at all
  8. Enqueue A, enqueue B, dequeue, enqueue C, dequeue, dequeue. What order leaves?

    • A, then B, then C
    • C, then B, then A
    • B, then A, then C
LightMySky · lightmysky.comW1-mt_4U1bT0JW4g-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

The line with no overtaking W1-mt_4U1bT0JW4g-s1

  1. 7 · The dequeue removes 4, leaving 7 ahead of 9.
  2. First in, first out · The longest waiter always leaves next.
  3. Reversed in the stack, arrival order in the queue · Opposite rules give opposite orders.
  4. Everything behind waits; cancel or restart the front job and the line flows in order · The front blocks all; front-only surgery unblocks it.
  5. One printer serves many in order · Arrival order keeps the shared printer fair.
  6. False · Front removal shifts everything along, so real programs use a double ended queue.
  7. Undo needs newest first, which is stack order, not queue order · Queues serve oldest first; undo must serve newest first.
  8. A, then B, then C · Each dequeue takes the current front: A, then B, then C.
Worksheet · LightMySky