Prefix, Postfix, Infix Notation
By Mrs. Dolly Dhall,Asstt. Prof. , MCA Deptt., SPGOI, Rtk
Infix Notation
To add A, B, we write
A+B
To multiply A, B, we write
A*B
The operators ('+' and '*') go in between
the operands ('A' and 'B')
This is "Infix" notation.
By Mrs. Dolly Dhall,Asstt. Prof. , MCA Deptt., SPGOI, Rtk
Prefix Notation
Instead of saying "A plus B", we could
say "add A,B " and write
+AB
"Multiply A,B" would be written
*AB
This is Prefix notation.
By Mrs. Dolly Dhall,Asstt. Prof. , MCA Deptt., SPGOI, Rtk
Postfix Notation
Another alternative is to put the
operators after the operands as in
AB+
and
AB*
This is Postfix notation.
By Mrs. Dolly Dhall,Asstt. Prof. , MCA Deptt., SPGOI, Rtk
Pre A In B Post
The terms infix, prefix, and postfix tell
us whether the operators go between,
before, or after the operands.
By Mrs. Dolly Dhall,Asstt. Prof. , MCA Deptt., SPGOI, Rtk
Parentheses
Evaluate 2+3*5.
+ First:
(2+3)*5 = 5*5 = 25
* First:
2+(3*5) = 2+15 = 17
Infix notation requires Parentheses.
By Mrs. Dolly Dhall,Asstt. Prof. , MCA Deptt., SPGOI, Rtk
What about Prefix Notation?
+2*35=
=+2*35
= + 2 15 = 17
* +235=
=*+235
= * 5 5 = 25
No parentheses needed!
By Mrs. Dolly Dhall,Asstt. Prof. , MCA Deptt., SPGOI, Rtk
Postfix Notation
235*+=
=235*+
= 2 15 + = 17
23+ 5*=
=23+5*
= 5 5 * = 25
No parentheses needed here either!
By Mrs. Dolly Dhall,Asstt. Prof. , MCA Deptt., SPGOI, Rtk
Conclusion:
Infix is the only notation that requires
parentheses in order to change the order
in which the operations are done.
By Mrs. Dolly Dhall,Asstt. Prof. , MCA Deptt., SPGOI, Rtk
Fully Parenthesized Expression
A FPE has exactly one set of Parentheses
enclosing each operator and its operands.
Which is fully parenthesized?
(A+B)*C
( ( A + B) * C )
( ( A + B) * ( C ) )
By Mrs. Dolly Dhall,Asstt. Prof. , MCA Deptt., SPGOI, Rtk
Infix to Prefix Conversion
Move each operator to the left of its
operands & remove the parentheses:
( ( A + B) * ( C + D ) )
By Mrs. Dolly Dhall,Asstt. Prof. , MCA Deptt., SPGOI, Rtk
Infix to Prefix Conversion
Move each operator to the left of its
operands & remove the parentheses:
(+A B *(C+D))
By Mrs. Dolly Dhall,Asstt. Prof. , MCA Deptt., SPGOI, Rtk
Infix to Prefix Conversion
Move each operator to the left of its
operands & remove the parentheses:
*+A B (C+D)
By Mrs. Dolly Dhall,Asstt. Prof. , MCA Deptt., SPGOI, Rtk
Infix to Prefix Conversion
Move each operator to the left of its
operands & remove the parentheses:
*+A B +C D
Order of operands does not change!
By Mrs. Dolly Dhall,Asstt. Prof. , MCA Deptt., SPGOI, Rtk
Infix to Postfix
(((A+B)*C)-((D+E)/F))
A B+C* D E+F/-
Operand order does not change!
Operators are in order of evaluation!
By Mrs. Dolly Dhall,Asstt. Prof. , MCA Deptt., SPGOI, Rtk