Episode 4
The Parade Printer Cuts the Line
The robot would like to get on with printing the duck pennant, but there's a prior job in the queue.






















Episode transcript
The parade print desk
Duck: We need the parade pennants with the names!
FRONT: nearest printer. BACK: new arrivals. EMPTY
Robot: Empty queue. There's nothing to print.
STAR job card appears.
FRONT [STAR] BACK
Robot: STAR first.
MOON is next to the STAR. DUCK is next to the MOON.
ARRIVALS: STAR → MOON → DUCK. FRONT [STAR, MOON, DUCK] BACK
Duck: Then MOON. Then MY DUCK!
A tempting cut-in
The robot's arm swings at the latest card, DUCK, in the back. It hasn't taken a card out or triggered the printer with the pincer.
Robot: That duck pennant looks nifty. I'll print that first.
Duck extends one of his wings in the direction of the STAR card in the front. The robot halts. No printing has been started. The order in the queue remains.
Duck: Wait! Someone had STAR ahead of me.
The robot traces a row that is waiting from STAR (in front) to MOON and DUCK (in back).
Robot: This desk does First Come, First Served.
The duck sees his DUCK card stays behind MOON.
FRONT [STAR, MOON, DUCK] BACK
Duck: STAR goes first. I have no problem waiting.
A new arrival
STAR goes into active printer. You see a star pennant come out of the printer. STAR is no longer in the waiting tray.
Robot: STAR is being printed.
FRONT [MOON, DUCK] BACK
Duck: MOON leads now.
New SUN card shows up!
FRONT [MOON, DUCK, SUN] BACK
Robot: SUN joins on the rear side.
Duck points at 3 pending cards. MOON is first, then DUCK, then SUN. Robot hesitates before picking up another card.
First in, first out
Robot grabs MOON from front. DUCK and SUN stay in order. Duck is nodding inside monitor.
ACTIVE: MOON. WAITING: DUCK, SUN
Robot: MOON.
Bot adds it after the STAR pennant. DUCK is the front waiting card now.
PRINTED: STAR, MOON. FRONT [DUCK, SUN] BACK
Duck: There goes MOON!
Robot takes off DUCK (in front) and prints a duck pennant. There's only SUN waiting.
PRINTED: STAR, MOON, DUCK. WAITING: SUN
Duck: My turn!
The robot pulls the last sun card out. It prints the sun pennant. There's nothing in the waiting tray. The four completed pennants are suspended in order STAR, MOON, DUCK, SUN.
PRINTED: STAR, MOON, DUCK, SUN. EMPTY
Robot: SUN ends the row.
No waiting jobs
The robot scans the empty wait tray. The four printed pennants are waving. There is no new card.
Duck: Any jobs available?
The robot holds back its pincer from the empty tray. It doesn't initiate another print. The duck observes the empty tray on the monitor.
Robot: None. We will sit it out until the next job comes in.
All of the jobs that were asked have been printed out once.
Robot: Good thing you stopped me jumping the queue.
First in, first out (FIFO)
A queue is an ordered waiting list of items. In this story, the items are print jobs waiting to be done.
A card and a printed pennant are two separate things. STAR is a card that says you want a pennant printed with the text STAR on it.
JOB CARD: STAR → PRINTED PENNANT: STAR
FRONT = HEAD. BACK = TAIL.
There is a head and tail of the waiting queue. Enqueue always adds the new item at the tail of the queue after the existing waiting jobs. Dequeue removes from the head (oldest waiting job) for printing. New items can never "jump" to the head before the items that have been waiting longer. So the relative waiting order between items never changes as new items come.
This desk uses FIFO. There may be priorities and cancellation rules on real printers.
Try a new queue
Answer
BOAT should be processed next (already waiting when TREE arrived).
WAITING: [BOAT, TREE] → TAKE BOAT → [TREE] → TAKE TREE → EMPTY
Stop processing when there are no jobs left to process.
In this case dequeuing means that you will take out something from the waiting queue to process it. The job you take out will not be canceled.
Sources
Paul E. Black, “queue”, NIST Dictionary of Algorithms and Data Structures (opens in a new tab)