Skip to main contentSkip to solution

In process of converting the infix expression A + B * C - D to postfix expression, what will be the correct order of stack operations?

(A). Push *

(B). Push +

(C). Pop * and + then Push -

(D). Pop -

Solution

✅ Correct Option: 2

Scan the expression from left to right. Operands go straight to the output, and an operator pops any stack operators of equal or higher precedence before it is pushed.

(B) Push +: the stack is empty, so + is pushed after A is output.

(A) Push *: * has higher precedence than +, so it is pushed on top without popping.

(C) Pop * and + then Push -: - has lower precedence than *, and equal precedence to + (left-associative), so both are popped before - is pushed.

(D) Pop -: at the end of the input, the remaining operator - is popped.

The resulting postfix expression is A B C ∗ + D −A\,B\,C\,*\,+\,D\,-

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question