GATE Computer ScienceVery hardGATE CS (PYQ pattern)

The infix expression a + b * (c ^ d - e) ^ (f + g * h) - i (with ^ right-associative and higher than * and +) is converted to postfix with the usual operator-stack algorithm. Counting '(' as a stack entry, what is the maximum number of symbols on the stack at any moment, and what is the 6th symbol of the postfix result?

  1. A. 5 and e
  2. B. 6 and e
  3. C. 6 and -
  4. D. 7 and ^

Correct answer: B. 6 and e

Postfix is abcd^e-fgh*+^*+i-. The stack is fullest while reading g * h: + * ^ ( + * (6 symbols); the sixth symbol is e.

More Programming and Data Structures (GATE) questions

Exams that ask this topic