You are on page 1of 13

POLISH NOTATIONS

Infix, Prefix & Postfix


Polish Notations
› Polish notation was invented in 1924 by Jan
Lukasiewicz
› Form for expressing arithmetic, logic and algebraic
equations
› 3 types
– Prefix +ab
– Infix a+b
– Postfix ab+
Why?

Parenthesis-free notation

• Equation shorter and easier to parse

easy to understand by Computer

• Evaluate according to priority of the operators (STACK)


Precedence of Operators Associativity
PRECEDENCE & () Left to Right
ASSOCIATIVITY ↑ Right to Left
*,/ Left to Right
• The precedence of an
operator specifies how +,- Left to Right
"tightly" it binds two
expressions together. For
example,
1 +5 * 3 =16
1 + 5 * 3 !=18
10↑2↑3
• The Associativity of an
operator specifies which
operator to solve first
between two operators of

10↑6 10↑8
same precedence.

10↑2↑3=10↑8
10↑2↑3!=10↑6
INFIX NOTATION
In-Order traversal of
• OPERAND Expression Tree
A
EXAMPLES:

• OPERATOR › A+(B*C-(D/E ↑F)*G)*H


+ › ((A+B↑C↑D)*(E+F/D)
› A*B/C+E/F*G+K-X*Y
• OPERAND › ~(p ^ q)⇔(~p v ~q)
B
-

EXPRESSION TREE
Expression Tree from infix * 3
notation involves recursive
step of making root of
expression tree the
operator that is to be 2 5
solved (least precedence)
at last and left
operation(expression)
becomes left child(tree)
and vice versa. i.e.,

2*5-3
INORDER:A*B/C+E/F*G+K-X*Y
-

+ *

+ K X Y

/ PREORDER: -++/*ABC*/EFGK*+K
*
POSTORDER:AB*C/EF/G*+K+XY*-
* C / G

A B
E F
PREFIX NOTATION
Pre-Order traversal of
• OPERATOR Expression Tree
+
EXAMPLES:

• OPERAND › +A-*BC**/D ↑EFGH


A › -++/*ABC*/EFGK*+K
› *+A↑B ↑C D+E/FD
• OPERAND › ⇔~^pqv~p~q
B
INORDER:A+(B*C-(D/E↑F)*G)*H
+

A *

- H

* PREORDER: +A*-*BC*/D↑EFGH
*
POSTORDER:ABC*DEF↑/G*-H*+
B C / G

D ↑

E F
POSTFIX NOTATION
Post-Order traversal of
• OPERAND Expression Tree
A
EXAMPLES:

• OPERAND › ABC*DEF↑/G*-H*+
B › AB*C/EF/G*+K+XY*-
› ABCD↑↑+EFD/+*
• OPERATOR › pq^~p~q~v⇔
+
INORDER:((A+B↑C↑D)*(E+F/D)

+ *

A ↑
E /
PREORDER: *+A↑B ↑C D+E/FD
POSTORDER: ABCD↑↑+EFD/+*
B ↑
F D

C D
POSTFIX , PREFIX
TO INFIX
• Start Evaluating from
Left to Right in postfix
notation. Find operator
and insert operator
between the operands
till end.
• Start Evaluating from
Right to Left in postfix
notation. Find operator
and insert operator
between the operands
till end.
Thank you!

You might also like