Reverse Polish Notation Flashcards
1
Q
what notation is RPN
A
postfix
2
Q
give two advantages of RPN
A
- no brackets to show correct order of calculation
- no backtracking when evaluating
- quicker for computers to evaluate
- no need for order of presedence
3
Q
give an example of the difference between postfix and infix
A
- postfix: 43+
- infix: 4+3
4
Q
describe the reverse polish pseudocode
A
- while tokens in RPN
- if next token is a value then add to stack
- else get operator, pop item off the stack and place to the right
- pop item of stack and place to the left
- place brackets around new expression and push it onto stack
- pop expression
5
Q
convert the following infix to postfix
3 + 11
A
311+
6
Q
convert the following infix to postfix
3 / (5+y*x)
A
35yx*+/
7
Q
how would the infix expression 3 + 4 * 2 - 1 be represented in RPN
A
34+2*1-