55. Reverse Polish notation Flashcards
convert the following reverse polish notation expression to its equivalent infix expression:
4 6 +
4 + 6
convert the following reverse polish notation expression to its equivalent infix expression:
8 2 -
8 -2
convert the following reverse polish notation expression to its equivalent infix expression:
4 9 + 6 x
(4 + 9) x 6
convert the following reverse polish notation expression to its equivalent infix expression:
10 4 7 + x
10 x (4 + 7)
convert the following reverse polish notation expression to its equivalent infix expression:
3 9 + 4 2 - x
(3 + 9) x (4 - 2)
convert the following infix notation expression to its equivalent reverse polish notation expression:
4 + 3
4 3 +
convert the following infix notation expression to its equivalent reverse polish notation expression:
56 - 40
56 40 -
convert the following infix notation expression to its equivalent reverse polish notation expression: 5 x (5 - 3)
5 5 3 - x
convert the following infix notation expression to its equivalent reverse polish notation expression:
(6 / 3) + (6 + 2)
6 3 / 6 2 + +
convert the following infix notation expression to its equivalent reverse polish notation expression:
(18 - 8) x (30 + 20)
18 8 - 30 20 + x
why do we use reverse polish notation?
it eliminates the need for brackets in sub-expressions
it produces expressions in a form suitable for evaluation using a stack
it is used in interpreters based on stack; for example, postscript and bytecode
operands and operators need to be in correct sequence for computer to execute
what do we refer to regular way we write arithmetic expressions as?
infix notation
another name for reverse polish notation?
postfix notation
what is the first step in translating from infix to reverse polish notation?
define the order of precedence of operators
e.g. = ( + - ) * / ^ ~
describe the evaluation of reverse polish notation using a stack
once a compiler has translated and arithmetic expression into RPN, each symbol in the expression may be held in a string or array
the expression may then be evaluated using a stack scanning the elements of the string (or array) from left to right
- if the next token is an operand, place it on the stack
- if the next token is an operator, remove the required number of the operands from the stack, perform the operation, and put the result on the stack