ITPEC IP April 2018 Question 5

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

ITPEC IP April 2018 — Question 5 of 100

After all four stack operations, the boxes are 2 on top of 1. Starting top-first with 4, 3, 2, 2, 1: operation 1 replaces 4 and 3 with 7; operation 2 pushes 3; operation 3 replaces 3, 7, 2 with their average 4; operation 4 replaces 4 and 2 with |4 - 2| = 2.

Answer (b)

Why not others:
- (a) incorrectly removes the remaining bottom box

- (c) shows the state before the final difference operation

- (d) does not reflect the boxes removed during the averaging and difference operations

Key rule: A stack is last-in, first-out: every take removes items from the top, and every new result is pushed back onto the top.

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.