ITPEC IP October 2019 Question 6
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 a value is removed twice continuously. Which of the following is the value that is obtained by the second removal?
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 value asked for
- •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 value obtained by the first removal, not the second
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.