ITPEC IP April 2023 Question 6

There is a series of numbered boxes stacked as shown in the figure below. The operations described in the table below are performed in the sequence of operations 1 through 4. When the operation 4 is completed, which of the following shows the status of the stacked boxes?

43221

Fig.

Table

OperationDescription
Operation 1Take two boxes from the top, add the numbers on the boxes, write the sum on a new box, and then put it on the top.
Operation 2Write the number 3 on a new box, and then put it on the top.
Operation 3Take three boxes from the top, calculate the average, write the average value on a new box, and then put it on the top.
Operation 4Take two boxes from the top, calculate the absolute value of the difference between the numbers on the boxes, write the absolute value on a new box, and then put it on the top.

Explanation

2 on top of 1 — the boxes form a stack: every operation takes boxes from the top and puts its result back on the top.

Top first, the stack starts as 4, 3, 2, 2, 1.

  • •Operation 1: take 4 and 3, put 4 + 3 = 7: 7, 2, 2, 1
  • •Operation 2: put 3: 3, 7, 2, 2, 1
  • •Operation 3: take 3, 7 and 2, put (3 + 7 + 2) ÷ 3 = 4: 4, 2, 1
  • •Operation 4: take 4 and 2, put 4 − 2 = 2: 2, 1

Answer (b)

Why not others:

  • •(a) 0 — one box; the operations take 2 + 3 + 2 = 7 boxes and add 4, so five boxes become two, not one
  • •(c) 4, 2, 1 — the stack after operation 3; operation 4 has not been applied
  • •(d) 1, 2, 2, 1 — four boxes, again contradicting the count of two

Key rule: A stack is last in, first out: all takes and puts happen at the top; counting boxes removed and added is a quick check on the final height.

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.