Reverse Polish Notation
Reverse Polish Notation@Oregonstate
An algebraic expression in Reverse Polish Notation is evaluated as follows.
- The expression is scanned from left to right.
- If a number is encountered, it is pushed onto the stack.
- If an operator is encountered, it is applied to the top two operands on the stack. After removing the operands used, the result is pushed onto the
stack.
- When you provide an expression to be evaluated, separate numbers and operators with spaces as 10 20 + 2 * 30 4 6 + + *.
(Courtesy of http://web.engr.oregonstate.edu/~minoura/cs261/)
Expression Tree@Oregonstate
An algebraic expression is represented as a tree and is evaluated.
- Each leaf node represents an operand.
- An internal node is an operator.
- A post-order traversal is performed over the nodes.
- In a post-order traversal, each node is visited after its descendant nodes are visited.
(Courtesy of http://web.engr.oregonstate.edu/~minoura/cs261/)
|