Presentation is loading. Please wait.

Presentation is loading. Please wait.

Department of Technical Education Andhra Pradesh

Similar presentations


Presentation on theme: "Department of Technical Education Andhra Pradesh"— Presentation transcript:

1 Department of Technical Education Andhra Pradesh
Name : B Vijaya Kumari Designation : Lecturer Branch : Computer Engineering Institute : Smt.B.Seetha Polytechinic, Bhimavaram Year/Semester : III SEM Subject : DATA STRUCTURES THROUGTH C Sub.Code : 9CM305 Topic : STACK Duration : 50 Minutes Subtopic : Conversion of Infix to Postfix Teaching Aids : ppt, Animations, Photographs Revised by : Bapuji naik 9CM305.25

2 Recap In the last class we have discussed about Stack operations and applications of Stack 9CM305.25

3 Objective After the end of this class you would be able to know
Expression Notations Infix, prefix, postfix expressions Convert infix to postfix expression 9CM305.25

4 Expression Notations Expression can be represented in three ways
Infix Notation Prefix Notation Postfix Notation 9CM305.25

5 Expression Notations Contin…..
Infix Expression: The Operators are placed between the Operands Example: A + B A,B are Operands and + is Operator + is placed between A and B 9CM305.25

6 Expression Notations Infix Expression Uses Contin…..
These expressions are used in mathematical calculations. Most commonly used notation 9CM305.25

7 Expression Notations Contin…..
Postfix Expression: The Operator s are placed after the Operands Also known as reverse Polish notation Example: AB+ Here A&B are Operands and + is an Operator + is placed after the Operands 9CM305.25

8 Conversion of Infix to Postfix
Contin….. Conversion of Infix to Postfix Prefix Expression: The Operators are placed before the Operands is known as Prefix Expression. And also known as Polish notation Example: + AB Here A&B are Operands and + is an Operator + is placed before the Operands 9CM305.25

9 Conversion of Infix to Postfix
Contin….. Conversion of Infix to Postfix Examples of Infix to Prefix and corresponding expressions 9CM305.25

10 Convert Infix Expression to Postfix notation
Contin….. Convert Infix Expression to Postfix notation Conversion of Infix to Postfix To convert Infix notation to Postfix the scan will be done character wise. From left to right A character is read each and every time. 9CM305.25

11 Conversion of Infix to Postfix
Contin….. Conversion of Infix to Postfix Operator Precedence table 9CM305.25

12 Conversion of Infix to Postfix
Contin….. Conversion of Infix to Postfix 9CM305.25

13 Conversion of Infix to Postfix
Contin….. Conversion of Infix to Postfix 9CM305.25

14 Rules to convert Infix to Postfix Expression
Contin….. Conversion of Infix to Postfix Rules to convert Infix to Postfix Expression The read character is an operand then put the operand into Postfix String. The read character is left parentheses then push that on to the Stack. The read character is an Operator then check the priorities of the operator. (a) If the top of the stack is left parenthesis or the stack is empty, then push the operator on to the stack 9CM305.25

15 Conversion of Infix to Postfix
Contin….. Conversion of Infix to Postfix (b) If the top of the stack is an operator then check for priorities If the priorities of the operator on the top of stack is greater than the priority operator read OR if the priority are same Pop the top stack operator and put it in to postfix string and push the operator read on to the stack. 9CM305.25

16 Conversion of Infix to Postfix
Contin….. Conversion of Infix to Postfix If the priority of the read Operator is greater than the priority of the operator on top of the stack Push read operator on to the stack 9CM305.25

17 Conversion of Infix to Postfix
Contin….. Conversion of Infix to Postfix (c) If the read character is a right parenthesis pop the operators from stack and put them into output till a left parentheses is encountered 9CM305.25

18 Conversion of Infix to Postfix
Contin….. Conversion of Infix to Postfix If the character read is an end expression, then pop all the elements from the stack and put them on to output string Example: Infix notation: a (b c). Postfix notation: a b c + * + * 9CM305.25

19 Conversion of Infix to Postfix
Contin….. Conversion of Infix to Postfix Example to Convert Infix to Postfix using stack a + (b*c) Read character Stack Output a Empty + ( +( b ab * +(* c abc ) abc* abc*+ 9CM305.25

20 Example how to Convert Infix to Postfix
Contin….. Conversion of Infix to Postfix Example how to Convert Infix to Postfix Infix expression: a + ( b c ) * empty stack Push + * ( ( + + + Postfix expression: 9CM305.25

21 Example how to Convert Infix to Postfix
Contin….. Conversion of Infix to Postfix Example how to Convert Infix to Postfix Infix expression: a + ( b c ) * Push ) * ( ( + + Postfix expression: a b c 9CM305.25

22 Conversion of Infix to Postfix
Contin….. Conversion of Infix to Postfix 9CM305.25

23 Conversion of Infix to Postfix
Contin….. Conversion of Infix to Postfix 9CM305.25

24 Conversion of Infix to Postfix
Contin….. Conversion of Infix to Postfix 9CM305.25

25 Examples to convert Infix to Postfix expression
Contin….. Conversion of Infix to Postfix Examples to convert Infix to Postfix expression 9CM305.25

26 Summary We have discussed about Infix,Postfix,Prefix Expressions
Algorithm for converting an Infix expression to Postfix notation Examples for conversion of Infix to Postfix Expression 9CM305.25

27 Quiz (a) a + b 1.Infix expression is Cont..... (b) + ab (c) ab +
(d) both a & b 9CM305.25

28 2.Which of the following has highest precedence?
Cont..... Quiz 2.Which of the following has highest precedence? (a) + , - (b) * . / (c) both a & b (d) none 9CM305.25

29 Quiz 3. Postfix expression is Cont..... (a) a + b (b) + ab (c) ab +
(d) both a & b 9CM305.25

30 4. Reverse polish notation is also called as
Cont..... Quiz 4. Reverse polish notation is also called as (a) Infix (b) prefix (c) postfix (d) none 9CM305.25

31 Quiz 5. Prefix expression is Cont..... (a) a + b (b) + ab (c) ab +
(d) both a & b 9CM305.25

32 Polish notation is also called as
Cont..... Quiz Polish notation is also called as (a) Infix (b) prefix (c) postfix (d) none 9CM305.25

33 Frequently Asked Questions
Explain how to convert an infix expression to postfix expression? Convert the following infix expression to postfix expression? (a) (a + b*c) / (c - d) (b) a/ (b + c)+ d * (e - f) Explain an algorithm for converting to infix postfix? 9CM305.25


Download ppt "Department of Technical Education Andhra Pradesh"

Similar presentations


Ads by Google