Open In App

Why do we need Prefix and Postfix notations?

Last Updated : 01 Jul, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads