INFIX, POSTFIX, PREFIX EXPRESSIONS

What is an Expression?

An Expression is a combination of operands (that can be numbers constants, variables), operators and symbols of grouping(brackets, curly braces) written is a specific format/way.

Types

Depending on how the expression is written, we can classify it into 3 types:

  1. Infix Expression: Expression in which the operator appears in between the operands and it is simply of the form (operand1 operator operand2).
    E.g. A+B
  2. Postfix Expression: Expression in which the operator appears after the operands and it is simply of the form (operand1 operand2 operator).
    E.g. AB+
  3. Prefix Expression: Expression in which the operator appears before the operands and is simply of the form (operator operand1 operand2).
    E.g. +AB

Order of Precedence & Associativity

Precedence & Associativity
Precedence Name Sybmols Associativity
1 Parentheses { } [ ] ( ) Same
2 Exponent ^ Right to Left
3 Division & Multiplication / * Left to Right
4 Addition & Subraction + - Left to Right

Need of these expressions

Infix expressions are human readable but not efficient for machine reading. Prefix and Postfix expressions do not need the concept of precedence & associativity hence it becomes highly efficient to parse expressions in prefix or postfix formats.

Will study the conversion of one type to another type & evaluation of expressions in seperate blog posts along with implemention using C++.

That's it from this blog post. If you liked it then do share this blog with your friends or people who wanna get into programming world. Thank You!

Copyright © NStF Blogs 2021