# Algorithm for Evaluation of postfix expression

Postfix expression also known as** Reverse Polish notation** (**RPN**) is a mathematical notation in which every operator follows all of its operands, in contrast to Polish notation (PN), which puts the operator before its operands. It is also known as **postfix notation**. It does not need any parentheses as long as each operator has a fixed number of operands.

Please go through this article before going further:

### Algorithm

- Read the postfix expression and start scanning from left to right.
- Create an empty stack
- Repeat the steps 4 – 5 until you reach the end of the postfix string.
- If the scanned token is an operand then push it into the stack.
- Else if it is an operator, check if it is a unary operator than pop one element from the stack apply unary operation and push back into the stack else if it is a binary operator then pop two elements from the stacks perform the operation and push the element back into the stack.
- At the end when we reach the end of the postfix expression we pop the final element from the stack as the result.

*OTHER RESOURCES*