SlideShare a Scribd company logo
1 of 7
ELECTRINICS & COMMUNICATION
ENGINEERING DEPARTMENT
TOPIC: EVALUATION OF POSTFIX EXPRESSION USING STACK
 Name : Shubhajit Chatterjee
 Student Code : BWU/BEC/19/028
 Registration Number : 19013000936 of 2019-2020
 Roll Number : 19010308024
 Course Name :Data Structures and Algorithm
 Course code : ESC(ECE)301
 Programme : Bachelor of Technology in Electronics & Communication Engineering
 Semester : 3rd
ELECTRINICS & COMMUNICATION
ENGINEERING DEPARTMENT
• What is Postfix Expression :
The ease of evaluation acts as the driving force for computers to translate
an infix notation into a postfix notation. That is, given an algebraic
expression written in infix notation, the computer first converts the
expression into the equivalent postfix notation and then evaluates the
postfix expression.
Both these tasks—converting the infix notation into postfix notation and
evaluating the postfix expression—make extensive use of stacks as the
primary tool.
Using stacks, any postfix expression can be evaluated very easily.
ELECTRINICS & COMMUNICATION
ENGINEERING DEPARTMENT
 Evaluation rule of a Postfix Expression states:
1.While reading the expression from left to right, push the element in the stack if it is an
operand.
2.Pop the two operands from the stack, if the element is an operator(*,+,-,/,..etc) and then
evaluate it.
3.Push back the result of the evaluation. Repeat it till the end of the expression.
ELECTRINICS & COMMUNICATION
ENGINEERING DEPARTMENT
 ALGORITHM FOR POSTFIX EXPRESSION:
STEP 1:- Add ‘#’ to postfix expression.
STEP 2:- Read postfix expression Left to Right until ‘#’ encountered
STEP 3:- If operand is encountered, push it onto Stack
[End If]
STEP 4:- If operator is encountered, Pop two elements
i) A->Top element
ii) B-> Next to Top element
iii) Evaluate B operator A
push B operator A onto Stack
STEP 5:- Set result = pop
STEP 6:- END
STEP INPUT OPERATION STACK CALCULATION
1 8 Push 8
2 4 Push 8,4
3 3 Push 8,4,3
4 * Pop(2elements) & evaluate 8 4*3=12
5 Push result(12) 8,12
6 6 Push 8,12,6
7 / Pop(2elements) & evaluate 8 12/6=2
8 Push result(2) 8,2
9 - Pop(2elements) & evaluate Empty 8-2=6
10 Push result(6) 6
11 No more elements(Pop) Empty 6 (Result)
ELECTRINICS & COMMUNICATION
ENGINEERING DEPARTMENT
 Evaluate Postfix Expression :843*6/-
ELECTRINICS & COMMUNICATION
ENGINEERING DEPARTMENT
o Example : 843*6/-
8
4
3
Push 8,4,3Stack is
empty
Top
Top
Pop 3,4
8
12
4*3=12
Push 12
Top
8
12
6
Push 6
Top
8
Pop 6,12
Top
12/6=2
Push 2
8
2
Top
Top
6
8-2=6
Push 6
Pop 2,8
Stack
empty
Pop6
Ans=6
8
Empty
ELECTRINICS & COMMUNICATION
ENGINEERING DEPARTMENT

More Related Content

What's hot

What's hot (20)

Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Unit I - Evaluation of expression
Unit I - Evaluation of expressionUnit I - Evaluation of expression
Unit I - Evaluation of expression
 
Queues
QueuesQueues
Queues
 
Stacks in Data Structure
Stacks in Data StructureStacks in Data Structure
Stacks in Data Structure
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
 
Stack - Data Structure
Stack - Data StructureStack - Data Structure
Stack - Data Structure
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
 
Stacks
StacksStacks
Stacks
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 
Stack
StackStack
Stack
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 

Similar to Evaluation of postfix expression using stack

Satish patil resume
Satish patil resumeSatish patil resume
Satish patil resume
satish patil
 
introductory-mechatronics-course-created-to-fulfill-a-freshman-level-engineer...
introductory-mechatronics-course-created-to-fulfill-a-freshman-level-engineer...introductory-mechatronics-course-created-to-fulfill-a-freshman-level-engineer...
introductory-mechatronics-course-created-to-fulfill-a-freshman-level-engineer...
Eric Vicente Rodríguez Mojica
 
Karner resource estimation for objectory projects
Karner   resource estimation for objectory projectsKarner   resource estimation for objectory projects
Karner resource estimation for objectory projects
Ocho08
 
EGR1013M Coursework 1 - Excel 2017-18.pdfPage 1 of 4 S.docx
EGR1013M Coursework 1 - Excel 2017-18.pdfPage 1 of 4 S.docxEGR1013M Coursework 1 - Excel 2017-18.pdfPage 1 of 4 S.docx
EGR1013M Coursework 1 - Excel 2017-18.pdfPage 1 of 4 S.docx
SALU18
 
Lec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptxLec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptx
haaamin01
 
The concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdfThe concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdf
arihantsherwani
 

Similar to Evaluation of postfix expression using stack (20)

CBCS 2018 Scheme I sem Lab Manual for 18CPL17
CBCS 2018 Scheme I sem Lab Manual for 18CPL17 CBCS 2018 Scheme I sem Lab Manual for 18CPL17
CBCS 2018 Scheme I sem Lab Manual for 18CPL17
 
C Programming Lab manual 18CPL17
C Programming Lab manual 18CPL17C Programming Lab manual 18CPL17
C Programming Lab manual 18CPL17
 
COMPILER DESIGN
COMPILER DESIGNCOMPILER DESIGN
COMPILER DESIGN
 
Satish patil resume
Satish patil resumeSatish patil resume
Satish patil resume
 
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORYGE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
 
Problem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CProblem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to C
 
Unit-I Algorithm.pptx
Unit-I Algorithm.pptxUnit-I Algorithm.pptx
Unit-I Algorithm.pptx
 
introductory-mechatronics-course-created-to-fulfill-a-freshman-level-engineer...
introductory-mechatronics-course-created-to-fulfill-a-freshman-level-engineer...introductory-mechatronics-course-created-to-fulfill-a-freshman-level-engineer...
introductory-mechatronics-course-created-to-fulfill-a-freshman-level-engineer...
 
Unit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptxUnit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptx
 
IRJET- Stress – Strain Field Analysis of Mild Steel Component using Finite El...
IRJET- Stress – Strain Field Analysis of Mild Steel Component using Finite El...IRJET- Stress – Strain Field Analysis of Mild Steel Component using Finite El...
IRJET- Stress – Strain Field Analysis of Mild Steel Component using Finite El...
 
Polish
PolishPolish
Polish
 
IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...
IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...
IRJET-Design and Implementation of LNS based Approximate Multiplier using Mit...
 
Topic 2_revised.pptx
Topic 2_revised.pptxTopic 2_revised.pptx
Topic 2_revised.pptx
 
Karner resource estimation for objectory projects
Karner   resource estimation for objectory projectsKarner   resource estimation for objectory projects
Karner resource estimation for objectory projects
 
slides5.ppt
slides5.pptslides5.ppt
slides5.ppt
 
EGR1013M Coursework 1 - Excel 2017-18.pdfPage 1 of 4 S.docx
EGR1013M Coursework 1 - Excel 2017-18.pdfPage 1 of 4 S.docxEGR1013M Coursework 1 - Excel 2017-18.pdfPage 1 of 4 S.docx
EGR1013M Coursework 1 - Excel 2017-18.pdfPage 1 of 4 S.docx
 
Lec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptxLec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptx
 
Unit 2 module-2
Unit 2 module-2Unit 2 module-2
Unit 2 module-2
 
The concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdfThe concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdf
 
SOFTWARE BASED CALCULATION OF CAPACITY OUTAGE OF GENERATING UNITS
SOFTWARE BASED CALCULATION OF CAPACITY OUTAGE OF GENERATING UNITSSOFTWARE BASED CALCULATION OF CAPACITY OUTAGE OF GENERATING UNITS
SOFTWARE BASED CALCULATION OF CAPACITY OUTAGE OF GENERATING UNITS
 

More from shubhajitCHATTERJEE2 (7)

Exclusive gates
Exclusive gatesExclusive gates
Exclusive gates
 
I-v charateristics of zener diode
I-v charateristics of zener diodeI-v charateristics of zener diode
I-v charateristics of zener diode
 
Z parameters
Z parametersZ parameters
Z parameters
 
Making of the constitution
Making of the constitutionMaking of the constitution
Making of the constitution
 
Maxwell's four equations in em theory
Maxwell's four equations in em theoryMaxwell's four equations in em theory
Maxwell's four equations in em theory
 
English communication and its purpose
English communication and its purposeEnglish communication and its purpose
English communication and its purpose
 
Impulse Response ppt
Impulse Response pptImpulse Response ppt
Impulse Response ppt
 

Recently uploaded

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Recently uploaded (20)

Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 

Evaluation of postfix expression using stack

  • 1. ELECTRINICS & COMMUNICATION ENGINEERING DEPARTMENT TOPIC: EVALUATION OF POSTFIX EXPRESSION USING STACK  Name : Shubhajit Chatterjee  Student Code : BWU/BEC/19/028  Registration Number : 19013000936 of 2019-2020  Roll Number : 19010308024  Course Name :Data Structures and Algorithm  Course code : ESC(ECE)301  Programme : Bachelor of Technology in Electronics & Communication Engineering  Semester : 3rd
  • 2. ELECTRINICS & COMMUNICATION ENGINEERING DEPARTMENT • What is Postfix Expression : The ease of evaluation acts as the driving force for computers to translate an infix notation into a postfix notation. That is, given an algebraic expression written in infix notation, the computer first converts the expression into the equivalent postfix notation and then evaluates the postfix expression. Both these tasks—converting the infix notation into postfix notation and evaluating the postfix expression—make extensive use of stacks as the primary tool. Using stacks, any postfix expression can be evaluated very easily.
  • 3. ELECTRINICS & COMMUNICATION ENGINEERING DEPARTMENT  Evaluation rule of a Postfix Expression states: 1.While reading the expression from left to right, push the element in the stack if it is an operand. 2.Pop the two operands from the stack, if the element is an operator(*,+,-,/,..etc) and then evaluate it. 3.Push back the result of the evaluation. Repeat it till the end of the expression.
  • 4. ELECTRINICS & COMMUNICATION ENGINEERING DEPARTMENT  ALGORITHM FOR POSTFIX EXPRESSION: STEP 1:- Add ‘#’ to postfix expression. STEP 2:- Read postfix expression Left to Right until ‘#’ encountered STEP 3:- If operand is encountered, push it onto Stack [End If] STEP 4:- If operator is encountered, Pop two elements i) A->Top element ii) B-> Next to Top element iii) Evaluate B operator A push B operator A onto Stack STEP 5:- Set result = pop STEP 6:- END
  • 5. STEP INPUT OPERATION STACK CALCULATION 1 8 Push 8 2 4 Push 8,4 3 3 Push 8,4,3 4 * Pop(2elements) & evaluate 8 4*3=12 5 Push result(12) 8,12 6 6 Push 8,12,6 7 / Pop(2elements) & evaluate 8 12/6=2 8 Push result(2) 8,2 9 - Pop(2elements) & evaluate Empty 8-2=6 10 Push result(6) 6 11 No more elements(Pop) Empty 6 (Result) ELECTRINICS & COMMUNICATION ENGINEERING DEPARTMENT  Evaluate Postfix Expression :843*6/-
  • 6. ELECTRINICS & COMMUNICATION ENGINEERING DEPARTMENT o Example : 843*6/- 8 4 3 Push 8,4,3Stack is empty Top Top Pop 3,4 8 12 4*3=12 Push 12 Top 8 12 6 Push 6 Top 8 Pop 6,12 Top 12/6=2 Push 2 8 2 Top Top 6 8-2=6 Push 6 Pop 2,8 Stack empty Pop6 Ans=6 8 Empty