ITPEC IP October 2023 Question 8

In the data structure called a queue that is suitable for performing first-in first-out (FIFO) processing, values are stored in the order of “8”, “1”, “6”, and “3”, and then two (2) values are removed consecutively. Which of the following is the last value that is removed?

Explanation

1 — a queue gives values back in the order they were stored, so two removals return 8, then 1.

After storing 8, 1, 6, 3, the queue holds them front to back in that order. Each removal takes the value at the front:

  • •1st removal: 8
  • •2nd removal: 1, the last value removed
  • •6 and 3 remain in the queue

Answer (a)

Why not others:

  • •(b) 3 — the value stored last; it would be removed first from a stack, not from a queue
  • •(c) 6 — the result for a stack (LIFO): pops return 3, then 6
  • •(d) 8 — the first value removed, not the last of the two

Key rule: A queue is first-in first-out, removing from the front; a stack is last-in first-out, removing the most recently stored value first.

Algorithm and Programming · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official IP past-paper collection or Report an issue.