Conventional notation, such as , is equivalent to infix notation. Postfix notation, also known as Reverse Polish notation, is a notation where the operands appear before their operators such as in the expression . The advantage of postfix notation is the unambiguity of the sequence of operations. In fact, parentheses are redundant in the notation.
Stacks are ideal data structures for converting infix to postfix expressions. We scan the infix expression from left to right and make decisions based on if the scanned symbol (generally called a ‘token’) is an operand or an operator. Operands are pushed to the output and operators are pushed to the stack; so, our decision is based on the precedence of the operator.
A left parenthesis on the stack is only removed if an incoming right parenthesis is found (unlike other operators such as + - ? *, that only follow precedence rules).
In the example below, we will look at how to convert the infix expression to postfix: