ITPEC IP October 2025 Question 7

Which of the following is the appropriate way for extracting data from a stack that stores multiple data?

Explanation

Data that was stored last is extracted first — a stack is last-in, first-out (LIFO): data is stored and extracted at the same end, the top.

Storing (push) puts an item on the top of the stack, and extracting (pop) takes the item currently on the top. Data pushed in the order 1, 2, 3 is popped as 3, 2, 1, like a pile of plates where only the top plate can be taken off.

Answer (b)

Why not others:

  • •(a) — extracting from any specified position regardless of the storing order is random access, as in an array; a stack gives access only to its top
  • •(c) — first stored, first extracted is a queue (FIFO), where data joins at the rear and leaves from the front
  • •(d) — extracting by the priority of a key is a priority queue, often built as a heap, not a stack

Key rule: A stack suits work where the most recent item must be handled first, such as undo, returning from nested function calls or matching brackets; a queue suits work served in order of arrival, such as print jobs.

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.