GATE Computer ScienceModerateGATE CS (PYQ pattern)

A zero-address stack machine evaluates the expression (a + b) × (c + d) + (e + f) × (g + h) with every operator commutative, so the operands of each operator may be evaluated in either order. What is the least stack depth needed (counting each pushed operand and each intermediate result)?

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

Correct answer: D. 4

Leaves need 1; a sum of two leaves needs 2; a product of two such subtrees needs 2 + 1 = 3 (equal needs add one); the final sum of two equal subtrees needs 3 + 1 = 4.

More Computer Organization and Architecture questions

Exams that ask this topic