SlideShare ist ein Scribd-Unternehmen logo
1 von 12
AAllggoorriitthhmmss aanndd DDaattaa 
SSttrruuccttuurreess 
Lecture 5 
Oxford University Data Structures Using C++ by Dr Varsha Patil Press © 2012
2 
Applications Of Stack 
 Convert infix expression to postfix and prefix 
expressions 
 Evaluate the postfix expression 
 Reverse a string 
 Check well-formed (nested) parenthesis 
 Reverse a string 
 Process subprogram function calls 
 Parse (analyze the structure) of computer programs 
 Simulate recursion 
 In computations like decimal to binary conversion 
 In Backtracking algorithms (often used in optimizations and 
in games)
3 
Expression Evaluation And 
Conversion 
 The most frequent application of stacks is in evaluation of 
arithmetic expressions. 
 An arithmetic expression is made up of operands, operators, 
and delimiters. 
 When higher level programming language came into 
existence one of the major difficulty faced by computer scientists 
was to generate machine language instruction, which would 
properly evaluate any arithmetic expression.
4 
Expression Evaluation 
 To fix the order of evaluation, assign to each operator a priority 
 Because even though we write expression in parenthesis, still 
we have a question in mind, about whether to evaluate which 
one bracket first 
 Once the priorities are assigned then within any pairs of 
parenthesis we can understand that operators with highest 
priority are to be evaluated first 
 While evaluating expression usually the following operation 
precedence is used
5 
The following operators are written is in descending 
order of their precedence: 
Exponentiation ^, Unary +, Unary –, and not ~ 
Multiplication * and division / 
Addition + and subtraction – 
<, £ , =, ¹, ³, > 
AND 
OR
6 
The Operators and priorities 
Data Structures in C++ by Dr. Varsha Patil Oxferd Univercity
7 
Polish Notation and Expression Conversion 
Polish Mathematician Han Lukasiewicz suggested a notation called 
pPolish notation, which gives two alternatives to represent an 
arithmetic expression, the notation are postfix and prefix notations 
The fundamental property of Polish notation is that the order in 
which the operations are to be performed is determined by the 
positions of the operators and operands in the expression. 
Hence the advantage is parenthesis is not required while writing 
expressions in pPolish notation
Oxford University Data Structures Using C++ by Dr Varsha Patil Press © 2012 
8 
The example ex…pression in various forms-infix, 
prefix and postfix 
The postfix expressions can be evaluated easily hence infix 
expression is converted into postfix expression using stack.
Oxford University Data Structures Using C++ by Dr Varsha Patil Press © 2012 
9 
Need of prefix and postfix expressions 
Evaluation of infix expression using computer needs proper code 
generation by compiler without any ambiguity and is difficult due to 
various aspects such as operators priority and associativity 
This problem can be overcome by writing or converting infix to alternate 
notation such as prefix or postfix 
The postfix and prefix expressions possess many advantages as listed
Oxford University Data Structures Using C++ by Dr Varsha Patil Press © 2012 
10 
The need for parenthesis as in infix expression is overcome in 
postfix and prefix Notations 
 The priority of operators is no longer relevant 
Order of evaluation depends on position of operator not on priority and 
associativity 
The expression evaluation process is much simpler than attempting a direct 
evaluation from infix notation.
Oxford University Data Structures Using C++ by Dr Varsha Patil Press © 2012 
11 
Postfix Expression Evaluation process 
The postfix expression may be evaluated by making a left to right scan, 
stacking operands, and evaluating operators using as operands the correct 
number from the stack and again placing the result again onto stack 
This evaluation process is much simpler than attempting a direct evaluation 
from infix notation 
Process continues till stack is not empty or on occurrence of a character # 
which denotes the end of expression
Oxford University Data Structures Using C++ by Dr Varsha Patil Press © 2012 
12 
Steps for manually converting expression from one 
notation to other 
1)Initially fully parenthesize the given infix expression. 
2) Use operator precedence and associability rules for the same 
3) Now move all operators so that they replace their corresponding right 
parenthesis; 
4)Finally delete all parentheses and we get the postfix expression

Weitere ähnliche Inhalte

Was ist angesagt?

Stack data structure
Stack data structureStack data structure
Stack data structure
Tech_MX
 
Nondeterministic Finite Automata
Nondeterministic Finite AutomataNondeterministic Finite Automata
Nondeterministic Finite Automata
Adel Al-Ofairi
 

Was ist angesagt? (20)

Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFDatabase Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
 
Unit 5 internal sorting &amp; files
Unit 5  internal sorting &amp; filesUnit 5  internal sorting &amp; files
Unit 5 internal sorting &amp; files
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
Unit I-Data structures stack & Queue
Unit I-Data structures stack & QueueUnit I-Data structures stack & Queue
Unit I-Data structures stack & Queue
 
Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)
 
Chapter 4 notes DBMS.pdf
Chapter 4 notes DBMS.pdfChapter 4 notes DBMS.pdf
Chapter 4 notes DBMS.pdf
 
Nondeterministic Finite Automata
Nondeterministic Finite AutomataNondeterministic Finite Automata
Nondeterministic Finite Automata
 
Unit I-Data Structures_Intoduction.pptx
Unit I-Data Structures_Intoduction.pptxUnit I-Data Structures_Intoduction.pptx
Unit I-Data Structures_Intoduction.pptx
 
Array data structure
Array data structureArray data structure
Array data structure
 
Theory of automata and formal language lab manual
Theory of automata and formal language lab manualTheory of automata and formal language lab manual
Theory of automata and formal language lab manual
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data Structure
 

Andere mochten auch

Data Structure
Data StructureData Structure
Data Structure
sheraz1
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examples
mua99
 
Advanced data structures using c++ 3
Advanced data structures using c++ 3Advanced data structures using c++ 3
Advanced data structures using c++ 3
Shaili Choudhary
 

Andere mochten auch (20)

Expression evaluation
Expression evaluationExpression evaluation
Expression evaluation
 
Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions
 
Data Structure
Data StructureData Structure
Data Structure
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examples
 
Infix prefix postfix expression -conversion
Infix  prefix postfix expression -conversionInfix  prefix postfix expression -conversion
Infix prefix postfix expression -conversion
 
4. Recursion - Data Structures using C++ by Varsha Patil
4. Recursion - Data Structures using C++ by Varsha Patil4. Recursion - Data Structures using C++ by Varsha Patil
4. Recursion - Data Structures using C++ by Varsha Patil
 
1. Fundamental Concept - Data Structures using C++ by Varsha Patil
1. Fundamental Concept - Data Structures using C++ by Varsha Patil1. Fundamental Concept - Data Structures using C++ by Varsha Patil
1. Fundamental Concept - Data Structures using C++ by Varsha Patil
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Notation
NotationNotation
Notation
 
Hub102 - Lesson4 - Data Structure
Hub102 - Lesson4 - Data StructureHub102 - Lesson4 - Data Structure
Hub102 - Lesson4 - Data Structure
 
เฉลยการวิชาโครงสร้างข้อมูล 1/2554: Array
เฉลยการวิชาโครงสร้างข้อมูล 1/2554: Arrayเฉลยการวิชาโครงสร้างข้อมูล 1/2554: Array
เฉลยการวิชาโครงสร้างข้อมูล 1/2554: Array
 
Circular queues
Circular queuesCircular queues
Circular queues
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1
 
Advanced data structures using c++ 3
Advanced data structures using c++ 3Advanced data structures using c++ 3
Advanced data structures using c++ 3
 
Structured query language functions
Structured query language functionsStructured query language functions
Structured query language functions
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Structured query language constraints
Structured query language constraintsStructured query language constraints
Structured query language constraints
 
Stack
StackStack
Stack
 
Lec5
Lec5Lec5
Lec5
 

Ähnlich wie stacks in algorithems and data structure

Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03
Avelin Huo
 
Although people may be very accustomed to reading and understanding .docx
Although people may be very accustomed to reading and understanding .docxAlthough people may be very accustomed to reading and understanding .docx
Although people may be very accustomed to reading and understanding .docx
milissaccm
 
This first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docxThis first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docx
abhi353063
 
conceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdf
conceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdfconceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdf
conceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdf
SahajShrimal1
 

Ähnlich wie stacks in algorithems and data structure (20)

Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03
 
Polish
PolishPolish
Polish
 
Lecture_04.2.pptx
Lecture_04.2.pptxLecture_04.2.pptx
Lecture_04.2.pptx
 
OOP in C++
OOP in C++OOP in C++
OOP in C++
 
Computer programming in C. Library functions in C.
Computer programming in C. Library functions in C.Computer programming in C. Library functions in C.
Computer programming in C. Library functions in C.
 
3. Stack - Data Structures using C++ by Varsha Patil
3. Stack - Data Structures using C++ by Varsha Patil3. Stack - Data Structures using C++ by Varsha Patil
3. Stack - Data Structures using C++ by Varsha Patil
 
Chapter 3.pptx
Chapter 3.pptxChapter 3.pptx
Chapter 3.pptx
 
Chapter 6 ds
Chapter 6 dsChapter 6 ds
Chapter 6 ds
 
Mycasestudy
MycasestudyMycasestudy
Mycasestudy
 
Although people may be very accustomed to reading and understanding .docx
Although people may be very accustomed to reading and understanding .docxAlthough people may be very accustomed to reading and understanding .docx
Although people may be very accustomed to reading and understanding .docx
 
INTERNSHIP REPORT.docx
 INTERNSHIP REPORT.docx INTERNSHIP REPORT.docx
INTERNSHIP REPORT.docx
 
Lect-5 & 6.pptx
Lect-5 & 6.pptxLect-5 & 6.pptx
Lect-5 & 6.pptx
 
This first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docxThis first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docx
 
conceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdf
conceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdfconceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdf
conceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdf
 
CTE 313 - Lecture 3.pptx
CTE 313 - Lecture 3.pptxCTE 313 - Lecture 3.pptx
CTE 313 - Lecture 3.pptx
 
theory of programming languages by shikra
theory of programming languages by shikratheory of programming languages by shikra
theory of programming languages by shikra
 
Python
PythonPython
Python
 
Intro to php
Intro to phpIntro to php
Intro to php
 
Automation Testing theory notes.pptx
Automation Testing theory notes.pptxAutomation Testing theory notes.pptx
Automation Testing theory notes.pptx
 
Introduction to programming languages part 2
Introduction to programming languages   part 2Introduction to programming languages   part 2
Introduction to programming languages part 2
 

Kürzlich hochgeladen

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Kürzlich hochgeladen (20)

OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 

stacks in algorithems and data structure

  • 1. AAllggoorriitthhmmss aanndd DDaattaa SSttrruuccttuurreess Lecture 5 Oxford University Data Structures Using C++ by Dr Varsha Patil Press © 2012
  • 2. 2 Applications Of Stack  Convert infix expression to postfix and prefix expressions  Evaluate the postfix expression  Reverse a string  Check well-formed (nested) parenthesis  Reverse a string  Process subprogram function calls  Parse (analyze the structure) of computer programs  Simulate recursion  In computations like decimal to binary conversion  In Backtracking algorithms (often used in optimizations and in games)
  • 3. 3 Expression Evaluation And Conversion  The most frequent application of stacks is in evaluation of arithmetic expressions.  An arithmetic expression is made up of operands, operators, and delimiters.  When higher level programming language came into existence one of the major difficulty faced by computer scientists was to generate machine language instruction, which would properly evaluate any arithmetic expression.
  • 4. 4 Expression Evaluation  To fix the order of evaluation, assign to each operator a priority  Because even though we write expression in parenthesis, still we have a question in mind, about whether to evaluate which one bracket first  Once the priorities are assigned then within any pairs of parenthesis we can understand that operators with highest priority are to be evaluated first  While evaluating expression usually the following operation precedence is used
  • 5. 5 The following operators are written is in descending order of their precedence: Exponentiation ^, Unary +, Unary –, and not ~ Multiplication * and division / Addition + and subtraction – <, £ , =, ¹, ³, > AND OR
  • 6. 6 The Operators and priorities Data Structures in C++ by Dr. Varsha Patil Oxferd Univercity
  • 7. 7 Polish Notation and Expression Conversion Polish Mathematician Han Lukasiewicz suggested a notation called pPolish notation, which gives two alternatives to represent an arithmetic expression, the notation are postfix and prefix notations The fundamental property of Polish notation is that the order in which the operations are to be performed is determined by the positions of the operators and operands in the expression. Hence the advantage is parenthesis is not required while writing expressions in pPolish notation
  • 8. Oxford University Data Structures Using C++ by Dr Varsha Patil Press © 2012 8 The example ex…pression in various forms-infix, prefix and postfix The postfix expressions can be evaluated easily hence infix expression is converted into postfix expression using stack.
  • 9. Oxford University Data Structures Using C++ by Dr Varsha Patil Press © 2012 9 Need of prefix and postfix expressions Evaluation of infix expression using computer needs proper code generation by compiler without any ambiguity and is difficult due to various aspects such as operators priority and associativity This problem can be overcome by writing or converting infix to alternate notation such as prefix or postfix The postfix and prefix expressions possess many advantages as listed
  • 10. Oxford University Data Structures Using C++ by Dr Varsha Patil Press © 2012 10 The need for parenthesis as in infix expression is overcome in postfix and prefix Notations  The priority of operators is no longer relevant Order of evaluation depends on position of operator not on priority and associativity The expression evaluation process is much simpler than attempting a direct evaluation from infix notation.
  • 11. Oxford University Data Structures Using C++ by Dr Varsha Patil Press © 2012 11 Postfix Expression Evaluation process The postfix expression may be evaluated by making a left to right scan, stacking operands, and evaluating operators using as operands the correct number from the stack and again placing the result again onto stack This evaluation process is much simpler than attempting a direct evaluation from infix notation Process continues till stack is not empty or on occurrence of a character # which denotes the end of expression
  • 12. Oxford University Data Structures Using C++ by Dr Varsha Patil Press © 2012 12 Steps for manually converting expression from one notation to other 1)Initially fully parenthesize the given infix expression. 2) Use operator precedence and associability rules for the same 3) Now move all operators so that they replace their corresponding right parenthesis; 4)Finally delete all parentheses and we get the postfix expression