GATE Computer ScienceHardGATE CS (PYQ pattern)

The expression a − (b − (c − (d − e))) is evaluated by a stack machine in which a binary operator takes the left operand from the second-from-top and the right operand from the top, so operands must be pushed left-to-right (no SWAP instruction). What stack depth is required?

  1. A. 3
  2. B. 5
  3. C. 2
  4. D. 4

Correct answer: B. 5

Subtraction is not commutative, so the push order is forced: a, b, c, d, e are all on the stack before the first subtraction, giving depth 5 (with commutative ops the inner term could be evaluated first, needing only 2).

More Computer Organization and Architecture questions

Exams that ask this topic