Professional Documents
Culture Documents
+,/,-,+,^ (operators)
Infix Notation
The operator symbol is placed between the two operands
Example:
A+B C-D (A+B)*C A+(B*C)
Disadvantage:
We must use
a. parenthesis
b. operator precedence rules
to evaluate the expression
Prefix Notation
In Prefix notation the operator is placed before the two
operands
Examples:
A+B +AB
C-D -CD
E*F *EF
G/H /GH
Prefix Example…
(a) (A+B)*C (b) A+(B*C)
A+
(+AB)*
(*BC)
C
*+ABC +A*BC
Prefix Notation Example…
(c) (A+B)/(C-D) Class Exercise
(d) 5 * ( 6 + 2 ) – 3 / 4
(+AB)/(-
CD) 5*(+62)-/34
-*5+62/34
Postfix Notation
In Postfix notation the operator is placed after the two
operands
Examples:
A+B AB+
C-D CD-
E*F EF*
G/H GH/
Postfix Example…
(a) (A+B)*C (b) A+(B*C)
A+
(AB+)*
(BC*)
C
AB+C* ABC*+
MoreExamples
(e) (A+B^D)/(E-F)+G
(A+BD^)/(EF-)
+G
ABD^+ / (EF-)+G
2. + 2. (+ 2. A
3. ( 3. (+( 3. A
4. B 4. (+( 4. AB
5. * 5. (+(* 5. AB
6. C 6. (+(* 6. ABC
7. - 7. (+(- 7. ABC*
8. ( 8. (+(-( 8. ABC*
9. D 9. (+(-( 9. ABC*D
S
T
A
C
K
Expression
Infix to postfix conversion
Postfix String: 1 2 3 * + 4 -
Infix to postfix conversion
Postfix String: 1 2 3 * + 4 -
1
Infix to postfix conversion
Postfix String: 1 2 3 * + 4 -
2
1
Infix to postfix conversion
Postfix String: 1 2 3 * + 4 -
3
2
1
Infix to postfix conversion
Postfix String: 1 2 3 * + 4 -
2*3=6
Infix to postfix conversion
Postfix String: 1 2 3 * + 4 -
6
1
Infix to postfix conversion
Postfix String: 1 2 3 * + 4 -
1+6=7
Infix to postfix conversion
Postfix String: 1 2 3 * + 4 -
7
Infix to postfix conversion
Postfix String: 1 2 3 * + 4 -
4
7
Infix to postfix conversion
Postfix String: 1 2 3 * + 4 -
7-4=3
Infix to postfix conversion
Postfix String: 1 2 3 * + 4 -