GATE Computer ScienceHardGATE CS (PYQ pattern)

Two stacks (values and operators) evaluate 12-(3+4*(5-2))/5*3+8/(1+1) with all operators left-associative and integer division truncating toward zero: before pushing an operator, apply stack operators of equal or higher precedence. What is the result, and what is the maximum height reached by the value stack?

  1. A. 10 and height 5
  2. B. 7 and height 5
  3. C. 7 and height 6
  4. D. 4 and height 4

Correct answer: B. 7 and height 5

Inside: 5 - 2 = 3, 4 * 3 = 12, 3 + 12 = 15; then 15 / 5 = 3, 3 * 3 = 9, 12 - 9 = 3, and 8 / 2 = 4, so the total is 7.

More Programming and Data Structures (GATE) questions

Exams that ask this topic