IB Computer Science HL · Year 2 · Lesson 3

Queues: FIFO Operations and Trade-offs

Explain queue behaviour, trace the four required operations, and justify when a FIFO structure fits a problem.

Paper 250 minutesB2.2.4
Today’s targets

What you need to be able to do

2 / 9
  • explain a queue as a first-in, first-out (FIFO) structure;
  • use and trace enqueue, dequeue, front and isEmpty accurately;
  • explain how queue operations affect performance and memory use;
  • justify whether a queue is appropriate for a specific problem.
B2.2.4
Paper 2 habitRead the command term and the data given. A technically correct answer still needs to answer the exact task.
Learn + retrieve

Rapid Recall Deck

3 / 9

Attempt each card first. If a term is new, flip and study it, then answer it again without looking. Mark only secure recall as “Know it”.

B2.2.4 · Explain

Trace a queue from front to rear

4 / 9
Starting queueFront → [A, B, C] ← Rear. The queue then performs enqueue(D), front(), dequeue(), enqueue(E), dequeue().

Trace the operations

After each operation — write the entire queue from front to rear.
For front/dequeue — also state the value returned. After the five operations, state the result of isEmpty().
  1. enqueue(D) → [A, B, C, D]
  2. front() returns A; queue stays [A, B, C, D]
  3. dequeue() returns A; queue becomes [B, C, D]
  4. enqueue(E) → [B, C, D, E]
  5. dequeue() returns B; queue becomes [C, D, E]

isEmpty() returns False because three items remain.

Operations

Front and rear have different jobs

5 / 9

Rear

enqueue adds a new item at the rear. New arrivals wait behind items that arrived earlier.

Front

dequeue removes the front item, while front inspects that item without removing it.

Explain FIFO precisely

A student says, “A queue always removes the newest item because that item is at the rear.” Explain the error.

Entry — identify where a newly arriving item is placed.
Removal — identify which end supplies the next item.
Ordering — explain what arrival order follows from those two rules.

New items are enqueued at the rear, but items are dequeued from the front. Therefore the item that has been in the queue the longest reaches the front first and is removed first. The newest item waits at the rear rather than leaving immediately.

Performance + memory

What changes as a queue grows?

6 / 9
PerformanceAn appropriate queue implementation keeps track of the front and rear, so enqueue and dequeue can work at the ends rather than scanning the whole queue.
MemoryEach waiting item consumes storage. Implementations may also use extra capacity, indices or links, so the representation affects overhead.

Explain the effect of heavy demand

A print queue grows from 3 jobs to 3,000 jobs while the printer processes only one job at a time. Explain one effect on memory and one reason the queue still preserves fair arrival order.

Memory — explain what changes when 3 waiting jobs become 3,000.
Service order — explain why growth does not change which waiting job should be served next.

Memory use increases because the queue must store information for many more waiting jobs. FIFO order is preserved because each new job is enqueued at the rear while the oldest waiting job is dequeued from the front.

Choose the structure

Queue or stack?

7 / 9
ScenarioA help desk wants tickets handled in the order they were submitted, unless a separate priority rule is introduced.

Explain why a queue fits the help-desk rule

A help desk wants tickets handled in the order they were submitted unless a separate priority rule is introduced. Explain why a queue fits that rule and why a stack would not.

Arrival — connect a submitted ticket to a queue operation.
Service — connect the next handled ticket to a queue operation.
Contrast — compare the resulting order with stack behaviour.

Each submitted ticket can be enqueued at the rear. The help desk then dequeues the ticket at the front, so the oldest waiting ticket is handled first. A stack would instead process the newest ticket first and would not match the required arrival order.

Do not overclaimA queue is appropriate because FIFO matches the requirement—not because queues are universally faster than other structures.
Exam lens

Teacher-created Paper 2 practice

8 / 9

1. A queue initially contains, from front to rear, [5, 8, 11]. Trace: enqueue(14), dequeue(), front(), enqueue(17).

2. Explain how front() differs from dequeue().

3. A network device buffers packets that should normally be forwarded in arrival order. Explain why FIFO queue behaviour is suitable.

  1. enqueue(14) → [5,8,11,14]; dequeue() returns 5 → [8,11,14]; front() returns 8 with no change; enqueue(17) → [8,11,14,17].
  2. front() returns the front item without removing it; dequeue() returns and removes the front item.
  3. Packets can be enqueued as they arrive and dequeued for forwarding from the front, preserving arrival order. This matches FIFO when no other scheduling rule overrides that order.
Homework

Finish the learning cycle

9 / 9

IA — main task

Continue refining the IA problem/planning material. Identify any data that arrives over time or needs to be processed in an order, and document the requirement without forcing a particular data structure yet.

Syllabus — short retrieval

Repeat only the queue cards marked “Review again”, then explain aloud why a printer queue is FIFO and an Undo history is LIFO.