Department of Technical Education Andhra Pradesh

Slides:



Advertisements
Similar presentations
INFIX, PREFIX, & POSTFIX EXPRESSIONS. Infix Notation We usually write algebraic expressions like this: a + b This is called infix notation, because the.
Advertisements

Stacks - 3 Nour El-Kadri CSI Evaluating arithmetic expressions Stack-based algorithms are used for syntactical analysis (parsing). For example.
Prefix, Postfix, Infix Notation
Arithmetic Expressions Infix form –operand operator operand 2+3 or a+b –Need precedence rules –May use parentheses 4*(3+5) or a*(b+c)
COSC 2006 Chapter 7 Stacks III
Joseph Lindo Abstract Data Types Sir Joseph Lindo University of the Cordilleras.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title : Overview of Stack.
Lecture 12 – ADTs and Stacks.  Modularity  Divide the program into smaller parts  Advantages  Keeps the complexity managable  Isolates errors (parts.
Topic 15 Implementing and Using Stacks
9CM Name :B Vijaya kumari Designation : Lecturer Branch :Computer Engineering Institute :Smt.B.Seetha. Polytechnic, Bhimavaram, Year/semester :III.
Infix to postfix conversion Process the tokens from a vector infixVect of tokens (strings) of an infix expression one by one When the token is an operand.
Infix, Postfix, Prefix.
Reverse Polish Expressions Some general observations about what they are and how they relate to infix expressions. These 9 slides provide details about.
Postfix notation. About postfix notation Postfix, or Reverse Polish Notation (RPN) is an alternative to the way we usually write arithmetic expressions.
CS 206 Introduction to Computer Science II 03 / 16 / 2009 Instructor: Michael Eckmann.
1 CSCD 326 Data Structures I Infix Expressions. 2 Infix Expressions Binary operators appear between operands: W - X / Y - Z Order of evaluation is determined.
Topic 15 Implementing and Using Stacks
More About Stacks: Stack Applications Dan Nguyen CS 146, Spring 2004 Professor Sin-Min Lee.
Evaluation of Expressions
The Stack and Queue Types Lecture 10 Hartmut Kaiser
Data Structures Lecture : Stacks (Infix, Postfix and Prefix Expressions) Azhar Maqsood NUST Institute of Information Technology (NIIT)
Stack Applications.
CSC 205 Programming II Postfix Expressions. Recap: Stack Stack features Orderly linear structure Access from one side only – top item Stack operations.
Computer Science Department Data Structure & Algorithms Problem Solving with Stack.
EC-211 DATA STRUCTURES LECTURE 8. STACK APPLICATIONS Infix, Prefix, and Postfix Expressions Example – Infix: A+B – Prefix: +AB – Postfix: AB+
Stack Applications Qamar Rehman.
Prefix, Postfix and Infix. Infix notation  A-B/(C+D)  evaluate C+D (call the result X),  then B/X (call the result Y),  and finally A-Y.  The order.
Stacks An Abstract Data Type. Restricted Access Unlike arrays, stacks only allow the top most item to be accessed at any time The interface of a stack.
CHP-3 STACKS.
Prefix, Postfix, Infix Notation. Infix Notation  To add A, B, we write A+B  To multiply A, B, we write A*B  The operators ('+' and '*') go in between.
Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data LIFO (Last In First Out) structure.
DATA STRUCTURES Application of Stack – Infix to Postfix conversion a Joshua Presentation.
CC 215 DATA STRUCTURES MORE ABOUT STACK APPLICATIONS Dr. Manal Helal - Fall 2014 Lecture 6 AASTMT Engineering and Technology College 1.
Applications of Stack Maitrayee Mukerji. Stacks Last In First Out (LIFO List) ◦ FILO? Insertions and Deletions from the same end called the Top Push(),
Lecture - 6(Stacks) On Data structures. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Lecture Outline What is a Stack? Array implementation of stacks Operations.
Review Use of Stack Introduction Stack in our life Stack Operations
Stacks Access is allowed only at one point of the structure, normally termed the top of the stack access to the most recently added item only Operations.
Revised based on textbook author’s notes.
COMPSCI 107 Computer Science Fundamentals
Infix to postfix conversion
Data Structures and Algorithms
Objectives In this lesson, you will learn to: Define stacks
CO4301 – Advanced Games Development Week 2 Introduction to Parsing
Data Structures and Algorithms
Copyright ©2012 by Pearson Education, Inc. All rights reserved
STACKS.
Stack application: postponing data usage
Algorithms and Data Structures
STACK CHAPTER 03 Developed By :- Misha Ann Alexander Data Structures.
Stacks – Calculator Application
Visit for more Learning Resources
Stacks – Calculator Application
PART II STACK APPLICATIONS
STACK IMPLEMENTATION Adam M.B..
Stacks Chapter 5 Adapted from Pearson Education, Inc.
Stacks, Queues, and Deques
More About Stacks: Stack Applications
Lecture No.07 Data Structures Dr. Sohail Aslam
Infix to Postfix Conversion
Stacks – Calculator Application
Queue Applications Lecture 31 Mon, Apr 9, 2007.
Infix to Postfix Conversion
Topic 15 Implementing and Using Stacks
(Part 2) Infix, Prefix & Postfix
Stack.
Queue Applications Lecture 31 Tue, Apr 11, 2006.
More About Stacks: Stack Applications
Chapter 7 (continued) © 2011 Pearson Addison-Wesley. All rights reserved.
Stacks A stack is an ordered set of elements, for which only the last element placed into the stack is accessible. The stack data type is also known as.
Presentation transcript:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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