0% found this document useful (0 votes)
29 views16 pages

4 - Expressions

Uploaded by

Boyina Viswanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views16 pages

4 - Expressions

Uploaded by

Boyina Viswanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Data Structures & Algorithms

Unit -3
Expressions

Pankaj Chandra
Assistant Professor
IT GGV
Expression
An expression can be defined as follows –

“An expression is a collection of


operators and operands that
represents a specific value”
Expression Types
Based on the operator position, expressions are
divided into THREE types. They are as follows -
1. Infix Expression
2. Postfix Expression
3. Prefix Expression
Infix Expression
In Infix expression, operator is used in between the
operands.
The general structure of an Infix expression is -
Operand1 Operator Operand2
Postfix Expression
In postfix expression, operator is used after
operands.
The general structure of an postfix expression is
- Operand1 Operand2 Operator
Prefix Expression
In prefix expression, operator is used before
operands.
The general structure of an prefix expression is -
Operator Operand1 Operand2
Expression
Every expression can be represented using all
the above three different types of expressions.
We can convert an expression from one form to
another form like Infix to Postfix, Infix to
Prefix etc.
Arithmetic Expression
Binary operations have different level of
precedence (priority)
1. Highest – Exponential (↑)
2.Next Highest – Multiplication(*) and Division(/)
3. Lowest – Addition(+) and Subtraction (-)
The operations on same level(precedence) are
performed from left to right.
Example – 4+2+3 = 6+3 = 9
8*2/8 = 16/8 = 2
Arithmetic Expression
Solve the Following Expression
2 ↑3+5*2 ↑2-12/6
Answer - 2 ↑3+5*2 ↑2-12/6
8+5*2 ↑2-12/6
8+5*4-12/6
8+20-12/6
8+20-2
28-2
26
Arithmetic Expression

Assignment

Solve the Following Expression


2 *5-8+7↑3+5*2 ↑2-12/6
Infix to Prefix and Postfix
Infix A+B*C
Prefix A+(*BC)
+A*BC
Postfix A+(BC*)
ABC*+

Infix (A+B)*C
Prefix (+AB)*C
*+ABC
Postfix (AB+)*C
AB+C*
Infix to Prefix and Postfix

Infix (A+B)/(C-D)
Prefix (+AB)/(-CD)
/+AB-CD
Postfix (AB+)/(CD-)
AB+CD-/
Infix to Prefix and Postfix

Infix A↑B*C+D/E↑F/G
Prefix A↑B*C+D/E↑F/G
(↑AB)*C+D/E↑F/G
(↑AB)*C+D/(↑EF)/G
(*↑ABC)+D/(↑EF)/G
(*↑ABC)+(/D↑EF)/G
(*↑ABC)+(//D↑EFG)
+*↑ABC//D↑EFG
Infix to Prefix and Postfix

Infix A↑B*C+D/E↑F/G
Postfix A↑B*C+D/E↑F/G
(AB↑)*C+D/E↑F/G
(AB↑)*C+D/(EF↑)/G
(AB↑C*)+D/(EF↑)/G
(AB↑C*)+(DEF↑/)/G
(AB↑C*)+(DEF↑/G/)
AB↑C*DEF↑/G/+
Infix to Prefix and Postfix

Assignment

Convert Infix to Prefix and Post Fix Notation


A+B+C/D-E*F ↑G ↑H ↑I
Thank You

You might also like