Prefix Notation:
Prefix notation is the notation in which operators are placed before the corresponding operands in the expression.
Example:
Infix notation: A + B
Prefix notation: +AB
Postfix Notation:
Postfix notation is the notation in which operators are placed after the corresponding operands in the expression.
Example:
Infix notation: A + B
Postfix notation: AB+
Need of Prefix and Postfix Notations:
- Prefix notations are needed when we require operators before the operands while postfix notations are needed when we require operators after the operands.
- Prefix notations are used in many programming languages like LISP.
- Prefix notations and Prefix notations can be evaluated faster than the infix notation.
- Postfix notations can be used in intermediate code generation in compiler design.
- Prefix and Postfix notations are easier to parse for a machine.
- With prefix and postfix notation there is never any question like operator precedence.
- There is no issue of left-right associativity.
Advantages of Postfix over Prefix Notations:
- Postfix notation has fewer overheads of parenthesis. i.e., it takes less time for parsing.
- Postfix expressions can be evaluated easily as compared to other notations.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!