Reverse polish notation for infix expression (A+B)∗C−D/E will be –
2022
Reverse polish notation for infix expression (A+B)∗C−D/E will be –
- A.
-*+ABC/DE
- B.
AB+CD-*E/
- C.
AB+C*DE-/
- D.
AB+C*DE/-
Attempted by 642 students.
Show answer & explanation
Correct answer: D
To convert the infix expression (A+B)*C−D/E to reverse polish notation (postfix), follow the order of operations and use a stack-based approach.
Step 1: Process (A+B).
- A and B are operands, so add them to the output: AB.
- The + operator is pushed to the stack.
- After processing, pop + to output: AB+.
Step 2: Multiply by C.
- C is an operand, so add to output: AB+C.
- The * operator is pushed to the stack.
- After processing, pop * to output: AB+C*.
Step 3: Process D/E.
- D is an operand, so add to output: AB+C*D.
- E is an operand, so add to output: AB+C*DE.
- The / operator is pushed to the stack.
- After processing, pop / to output: AB+C*DE/.
Step 4: Process the final subtraction.
- The - operator is pushed to the stack.
- After processing, pop - to output: AB+C*DE/-.
Final postfix expression: AB+C*DE/-.