Question: Reverse Polish Notation Reverse Polish Notation (RPN), also known as polish postfix notation or simply postfix notation, is a mathematical notation in which operators follow
Reverse Polish Notation Reverse Polish Notation (RPN), also known as polish postfix notation or simply postfix notation, is a mathematical notation in which operators follow their operands. For example, the infix expression P1: 5(1 2) 4)-3 can be written like this in Reverse Polish Notation: P2: 512+4+3- In terms of the operation, the expression P1 and P2 can be evaluated as P1 P2 5+((1+2)* 4)-3 512+4 +3- 5+(3 4)-3 5+12-3 17-3 14 534 +3- 5 12+3- 173- 14 The reverse polish notation has many advantages, such as there is no bracket in the expression and no priority js needed for the operators, most importantly, the evaluation proces? is quite simple. The reverse polish notation could be evaluated by using a stack. Evaluation Algorithm Stack Remark 5,1 ation Push Push Push Addition 5,3 Pop (1.2), do addition, push in the result (3 Push 5,3.4 Multiplication 5.12 Addition Pop (3.4), do multiplication, push in the result (12) 17 17.3 Push Subtraction 114 Pop (17.3), do subtraction, push in the result (24
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
