The Wayback Machine - https://web.archive.org/web/20230328060921/https://www.geeksforgeeks.org/why-do-we-need-prefix-and-postfix-notations/
Skip to content
Related Articles
Open in App
Not now

Related Articles

Why do we need Prefix and Postfix notations?

Improve Article
Save Article
Like Article
  • Difficulty Level : Basic
  • Last Updated : 01 Jul, 2022
Improve Article
Save Article
Like Article

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.
My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!