GATE Computer ScienceVery hardGATE CSE

Infix a+b*c^d^e-(f+g)*h/i^j^k is converted to postfix with the usual stack algorithm: operators and "(" are pushed on a stack, an operator pops stack operators of higher precedence or of equal precedence (when left-associative), and ^ is right-associative with highest precedence. What is the maximum number of symbols (operators and parentheses) on the stack at any instant?

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

Correct answer: D. 4

The postfix result is abcde^^*+fg+h*ijk^^/-; tracing the stack the peak size is 4 .

More Programming and Data Structures (GATE) questions

Exams that ask this topic