ITPEC IP April 2026 Question 5

Source exam: ITPEC IP April 2026Topic: Algorithm and Programming

ITPEC IP April 2026 — Question 5 of 100

A stack containing 2 above 1 — trace every operation from the top and preserve the untouched lower boxes.

Write the stack from bottom to top. It starts as [1, 2, 2, 3, 4].

  • Operation 1 removes 4 and 3, then pushes 7: [1, 2, 2, 7]
  • Operation 2 pushes 3: [1, 2, 2, 7, 3]
  • Operation 3 removes 3, 7, 2; their average is 4, so [1, 2, 4]
  • Operation 4 removes 4 and 2; |4 − 2| = 2, so [1, 2]

Answer (b)

Why not others:
- (a) drops the bottom box and incorrectly produces 0

- (c) leaves the original top value 4, although it was consumed in operation 1

- (d) leaves too many boxes; every multi-box operation replaces its inputs with one result

Key rule: For a stack, only the top items are removed. After each operation, record the whole stack before continuing.

AI-generated — may contain errors

The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.

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.