SlideShare a Scribd company logo
Ms.M.Karthiga
AP/CSE
EVOCATION
Topic 2_revised.pptx
 To apply the stack operations for solving
various applications.
1. Classify the various applications of Stack ADT.
(U/C)
2. Convert an infix expression to postfix
expression using Stack Data Structure. (Ap/C)
3. Compute the given postfix expression using
Stack ADT. (Ap/C)
4. Demonstrate backtracking approach using
Stack ADT with examples. (Ap/C)
Topic 2_revised.pptx
Four common stack applications are:
 Reversing data,
 Parsing,
 Postponing and
 Backtracking
 Reversing - {1 2 3 4} becomes {4 3 2 1}
Examples:
 Reversing a list
 Convert decimal to binary
Topic 2_revised.pptx
91 16 7 5 3
Pseudocode
1 read (number)
2 loop (number > 0)
1 set digit to number modulo 2
2 print (digit)
3 set number to quotient of number / 2
3 end loop
Input:10
Output:0101 which is reverse of 1010STACK
Topic 2_revised.pptx
 Parsing is any logic that breaks an expression of
data into independent pieces for further
processing.
 One common programming problem is
unmatched parentheses in an algebraic
expression.
 When parentheses are unmatched, two types
of errors can occur: the opening parenthesis
can be missing or the closing parenthesis can
be missing
Topic 2_revised.pptx
Solution using STACK:
 Whenever we find an opening parentheses in
a program, we push it into the stack.
 When we find a closing parentheses, we pop
its matching opening parentheses from the
stack
Topic 2_revised.pptx
 A stack can be useful when the application
requires that the use of data be postponed
for a while.
Examples:
 Infix to postfix transformation
 Postfix expression evaluation
Formats for arithmetic expressions:
1. Infix expression
 The operator comes between the operands.
 Ex: A+B
2. Prefix expression
 The operator comes before the operands.
 Ex: +AB
3. Postfix expression
 The operator comes after the operands.
 Ex: AB+
In the infix notation, we need to use
parentheses to control the evaluation
of the operators.
We thus have an evaluation method that
includes parentheses and two operator
priority classes.
 Priority 2 : * /
 Priority 1 : + -
 Priority 0 : (
1. Fully parenthesize the expression using any
explicit parentheses and the arithmetic
precedence.
2. Change all infix notations in each
parenthesis to postfix notation, starting
from the innermost expressions.
Conversion to postfix notation is done by
moving the operator to the location of the
expression’s closing parenthesis.
3. Remove all parentheses.
Infix expression  A+B*C
 Step 1
 (A+(B*C))
 Step 2
 (A+(BC*))
 (A(BC*)+)
 Step 3
 ABC*+  Postfix expression
Infix expression  (A+B)*C+D+E*F-G
 Step 1
 (((((A+B)*C)+D)+(E*F))-G)
 Step 2
 (((((AB+)*C)+D)+(EF*))-G)
 (((((AB+)C*)+D)+(EF*))-G)
 (((((AB+)C*)D+)+(EF*))-G)
 (((((AB+)C*)D+)(EF*)+)-G)
 (((((AB+)C*)D+)(EF*)+)G-)
 Step 3
 AB+C*D+EF*+G-  Postfix expression
 Keep track of operators in the infix expression
 If any operand is found, append it to the output
expression
 If any operator is found, push it into the stack
such that:
 If its priority is higher than the operator at the
top of the stack, go ahead and push it onto the
stack.
 If the current operator’s priority is lower than
or equal to that of the operator at the top of
the stack than, then top operator is popped out
of stack and placed in the output expression;
thus the current operator becomes top operator.
 Conversion of Infix to Postfix
 Step 1: Consider the next element in the input.
 Step 2: If it is operand, display it.
 Step 3: If it is opening parenthesis, insert it on
stack.
 Step 4: If it is an operator, then If stack is empty,
insert operator on stack.
 If the top of stack is opening parenthesis, insert the
operator on stack
 If it has higher priority than the top of stack, insert the
operator on stack.
 Else, delete the operator from the stack and display it,
repeat Step 4
 Step 5: If it is a closing parenthesis, delete
the operator from stack and display them
until an opening parenthesis is encountered.
Delete and discard the opening parenthesis.
 Step 6: If there is more input, go to Step
 Step 7: If there is no more input, delete the
remaining operators to output.
 Infix  A+B*C-D/E
 Postfix ABC*+DE/-
3*3/(4-1)+6*2 expression into postfix form
So, the Postfix Expression is 33*41-/62*+
 Backtracking is another stack use found in
applications such as computer gaming,
decision analysis, and expert systems.
Examples:
 Goal Seeking
 Eight Queens Problem
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
Topic 2_revised.pptx
 The postfix form of the expression
(A+B)∗(C∗D-E)∗F/G is:
A) AB+CD ∗ E−FG/∗∗
B) AB+CD ∗ E−F∗∗G/
C) AB+CD ∗ E−∗F∗G/
D) AB+CDE∗ −∗F∗G/
A) AB+CD ∗ E−FG/∗∗
 The postfix expression for the infix
expression a+b*(c+d)/f+d*e is:
A) ab+cd+*f/d+e*
B) abcd+*f/+de*+
C) a*b+cd/f*de++
D) both (B) and (C)
 B)abcd+*f/+de*+
 Evaluate the postfix expression:
5 2 / 4 + 5 * 2 +
 Ans:32
Topic 2_revised.pptx
Applications of stack
Reversing data
Reversing list
Convert decimal to binary
Parsing
Unmatched Parentheses
Postponement
Infix to postfix conversion
Evaluating postfix expression
Backtracking
Goal seeking
Eight queens problem
STACK
Definition
Operations
Implementation using array
PUSH POP STACK TOP
 Stack
 Definition
 Operations
 Push
 Pop
 Stack top
 Stack implementation using array
 Stack implementation using Linked List
Topic 2_revised.pptx

More Related Content

PPTX
Application of Stack - Yadraj Meena
Dipayan Sarkar
 
PPTX
Applicationofstack by Ali F.RAshid
ali rashid
 
PPTX
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Prakash Zodge
 
PPTX
STACK Applications in DS
NARESH GUMMAGUTTA
 
PPTX
STACK APPLICATIONS: INFOX TO POSTFIX CONVERSION AND EVALUATION OF POSTFIX EXP...
devismileyrockz
 
PPT
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
aamirali1061a
 
PPT
Stack
Tejas Patel
 
PPTX
Lec5-Stack-bukc-28022024-112316am (1) .pptx
haaamin01
 
Application of Stack - Yadraj Meena
Dipayan Sarkar
 
Applicationofstack by Ali F.RAshid
ali rashid
 
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Prakash Zodge
 
STACK Applications in DS
NARESH GUMMAGUTTA
 
STACK APPLICATIONS: INFOX TO POSTFIX CONVERSION AND EVALUATION OF POSTFIX EXP...
devismileyrockz
 
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
aamirali1061a
 
Lec5-Stack-bukc-28022024-112316am (1) .pptx
haaamin01
 

Similar to Topic 2_revised.pptx (20)

PDF
Data Structures And Algorithms(stacks queues)
lahariit406
 
PDF
Applications of Stack
Christalin Nelson
 
PPTX
Stack Data Structure Intro and Explanation
RitikaLohiya2
 
PPT
Stack in Data Structure
Usha P
 
PPSX
Data structure_Stack Introduction & app.
AnuradhaJadiya1
 
PPTX
Lecture_04.2.pptx
RockyIslam5
 
PPTX
Data strutcure and annalysis topic stack
MihirMishra36
 
PPT
data structure and algorithm by bomboat_3
jateno3396
 
PPTX
Data Structure and Algorithms by Sabeen Memon03.pptx
msoomar8611
 
PPT
Stack application
Student
 
PPTX
DS MOD2 (1) (1).pptx
kumarkaushal17
 
PDF
Applications of stack
A. S. M. Shafi
 
PPTX
COMP1603 Stacks and RPN 2023 Recording (2).pptx
asdadad5
 
PPTX
DSA_chapter_04_Stack and data structure and Queue.pptx
tahliildhoore54
 
PPTX
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
PPT
MO 2020 DS Stacks 3 AB.ppt
shashankbhadouria4
 
PPTX
Data Structures and Agorithm: DS 08 Infix to Postfix.pptx
RashidFaridChishti
 
PPTX
Prefix, Infix and Post-fix Notations
Afaq Mansoor Khan
 
PPTX
Unit 3 Stacks and Queues.pptx
Yogesh Pawar
 
Data Structures And Algorithms(stacks queues)
lahariit406
 
Applications of Stack
Christalin Nelson
 
Stack Data Structure Intro and Explanation
RitikaLohiya2
 
Stack in Data Structure
Usha P
 
Data structure_Stack Introduction & app.
AnuradhaJadiya1
 
Lecture_04.2.pptx
RockyIslam5
 
Data strutcure and annalysis topic stack
MihirMishra36
 
data structure and algorithm by bomboat_3
jateno3396
 
Data Structure and Algorithms by Sabeen Memon03.pptx
msoomar8611
 
Stack application
Student
 
DS MOD2 (1) (1).pptx
kumarkaushal17
 
Applications of stack
A. S. M. Shafi
 
COMP1603 Stacks and RPN 2023 Recording (2).pptx
asdadad5
 
DSA_chapter_04_Stack and data structure and Queue.pptx
tahliildhoore54
 
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
MO 2020 DS Stacks 3 AB.ppt
shashankbhadouria4
 
Data Structures and Agorithm: DS 08 Infix to Postfix.pptx
RashidFaridChishti
 
Prefix, Infix and Post-fix Notations
Afaq Mansoor Khan
 
Unit 3 Stacks and Queues.pptx
Yogesh Pawar
 
Ad

More from JAYAPRIYAR7 (20)

PPTX
ENVIRONMENTkjnolnkkhbkbkbkbkbkbb PPT.pptx
JAYAPRIYAR7
 
PDF
sihppt-191112hbihbikbkbkhbikbbhb192529.pdf
JAYAPRIYAR7
 
PPTX
TECH WARRIORS_SMART BIOSPHERE MONITORING SYSTEM.pptx
JAYAPRIYAR7
 
PPT
1.5 Energy Resources.ppt
JAYAPRIYAR7
 
PPTX
1.3 Incremental Model.pptx
JAYAPRIYAR7
 
PPT
1.1 The nature of software.ppt
JAYAPRIYAR7
 
PPTX
1.2 Waterfall model.pptx
JAYAPRIYAR7
 
PPTX
1.4 Prototyping model.pptx
JAYAPRIYAR7
 
PPTX
1.5 Spiral model.pptx
JAYAPRIYAR7
 
PPT
JP ASSIGNMENT SERIES PPT.ppt
JAYAPRIYAR7
 
PPT
Physiology_Endocrinology.ppt
JAYAPRIYAR7
 
PPTX
ICMRI PPT Template.pptx
JAYAPRIYAR7
 
PPTX
Indian Space Programme JP PPT.pptx
JAYAPRIYAR7
 
PPTX
ARCATHON SAMPLE PPT (REFERENCE MODEL).pptx
JAYAPRIYAR7
 
PPTX
SPEAKING ASSESSMENT PPT .pptx
JAYAPRIYAR7
 
PPTX
Engineering Students - Idea Submission Template.pptx
JAYAPRIYAR7
 
PPTX
TECH WARRIORS_INNOVATE FOR SOCIETY.pptx
JAYAPRIYAR7
 
PPTX
BOB_Sample_PPt_Template_(1).pptx
JAYAPRIYAR7
 
PDF
coursera1.pdf
JAYAPRIYAR7
 
PPT
neurotansmitters.ppt
JAYAPRIYAR7
 
ENVIRONMENTkjnolnkkhbkbkbkbkbkbb PPT.pptx
JAYAPRIYAR7
 
sihppt-191112hbihbikbkbkhbikbbhb192529.pdf
JAYAPRIYAR7
 
TECH WARRIORS_SMART BIOSPHERE MONITORING SYSTEM.pptx
JAYAPRIYAR7
 
1.5 Energy Resources.ppt
JAYAPRIYAR7
 
1.3 Incremental Model.pptx
JAYAPRIYAR7
 
1.1 The nature of software.ppt
JAYAPRIYAR7
 
1.2 Waterfall model.pptx
JAYAPRIYAR7
 
1.4 Prototyping model.pptx
JAYAPRIYAR7
 
1.5 Spiral model.pptx
JAYAPRIYAR7
 
JP ASSIGNMENT SERIES PPT.ppt
JAYAPRIYAR7
 
Physiology_Endocrinology.ppt
JAYAPRIYAR7
 
ICMRI PPT Template.pptx
JAYAPRIYAR7
 
Indian Space Programme JP PPT.pptx
JAYAPRIYAR7
 
ARCATHON SAMPLE PPT (REFERENCE MODEL).pptx
JAYAPRIYAR7
 
SPEAKING ASSESSMENT PPT .pptx
JAYAPRIYAR7
 
Engineering Students - Idea Submission Template.pptx
JAYAPRIYAR7
 
TECH WARRIORS_INNOVATE FOR SOCIETY.pptx
JAYAPRIYAR7
 
BOB_Sample_PPt_Template_(1).pptx
JAYAPRIYAR7
 
coursera1.pdf
JAYAPRIYAR7
 
neurotansmitters.ppt
JAYAPRIYAR7
 
Ad

Recently uploaded (20)

PDF
Chad Readey - An Independent Thinker
Chad Readey
 
PDF
The_Future_of_Data_Analytics_by_CA_Suvidha_Chaplot_UPDATED.pdf
CA Suvidha Chaplot
 
PPTX
Azure Data management Engineer project.pptx
sumitmundhe77
 
PPTX
GR3-PPTFINAL (1).pptx 0.91 MbHIHUHUGG,HJGH
DarylArellaga1
 
PPTX
Introduction to Biostatistics Presentation.pptx
AtemJoshua
 
PDF
Research about a FoodFolio app for personalized dietary tracking and health o...
AustinLiamAndres
 
PDF
Master Databricks SQL with AccentFuture – The Future of Data Warehousing
Accentfuture
 
PDF
AI Lect 2 Identifying AI systems, branches of AI, etc.pdf
mswindow00
 
PDF
A Systems Thinking Approach to Algorithmic Fairness.pdf
Epistamai
 
PPT
Chapter 2 METAL FORMINGhhhhhhhjjjjmmmmmmmmm
JanakiRaman206018
 
PPTX
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
abhinavmemories2026
 
PPTX
Logistic Regression ml machine learning.pptx
abdullahcocindia
 
PDF
CH2-MODEL-SETUP-v2017.1-JC-APR27-2017.pdf
jcc00023con
 
PPTX
Global journeys: estimating international migration
Office for National Statistics
 
PDF
TIC ACTIVIDAD 1geeeeeeeeeeeeeeeeeeeeeeeeeeeeeer3.pdf
Thais Ruiz
 
PDF
1 Simple and Compound Interest_953c061c981ff8640f0b8e733b245589.pdf
JaexczJol060205
 
PDF
Nashik East side PPT 01-08-25. vvvhvjvvvhvh
mandar401157
 
PPTX
artificial intelligence deeplearning-200712115616.pptx
revathi148366
 
PDF
Company Presentation pada Perusahaan ADB.pdf
didikfahmi
 
PPTX
Data-Driven-Credit-Card-Launch-A-Wells-Fargo-Case-Study.pptx
sumitmundhe77
 
Chad Readey - An Independent Thinker
Chad Readey
 
The_Future_of_Data_Analytics_by_CA_Suvidha_Chaplot_UPDATED.pdf
CA Suvidha Chaplot
 
Azure Data management Engineer project.pptx
sumitmundhe77
 
GR3-PPTFINAL (1).pptx 0.91 MbHIHUHUGG,HJGH
DarylArellaga1
 
Introduction to Biostatistics Presentation.pptx
AtemJoshua
 
Research about a FoodFolio app for personalized dietary tracking and health o...
AustinLiamAndres
 
Master Databricks SQL with AccentFuture – The Future of Data Warehousing
Accentfuture
 
AI Lect 2 Identifying AI systems, branches of AI, etc.pdf
mswindow00
 
A Systems Thinking Approach to Algorithmic Fairness.pdf
Epistamai
 
Chapter 2 METAL FORMINGhhhhhhhjjjjmmmmmmmmm
JanakiRaman206018
 
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
abhinavmemories2026
 
Logistic Regression ml machine learning.pptx
abdullahcocindia
 
CH2-MODEL-SETUP-v2017.1-JC-APR27-2017.pdf
jcc00023con
 
Global journeys: estimating international migration
Office for National Statistics
 
TIC ACTIVIDAD 1geeeeeeeeeeeeeeeeeeeeeeeeeeeeeer3.pdf
Thais Ruiz
 
1 Simple and Compound Interest_953c061c981ff8640f0b8e733b245589.pdf
JaexczJol060205
 
Nashik East side PPT 01-08-25. vvvhvjvvvhvh
mandar401157
 
artificial intelligence deeplearning-200712115616.pptx
revathi148366
 
Company Presentation pada Perusahaan ADB.pdf
didikfahmi
 
Data-Driven-Credit-Card-Launch-A-Wells-Fargo-Case-Study.pptx
sumitmundhe77
 

Topic 2_revised.pptx

  • 4.  To apply the stack operations for solving various applications.
  • 5. 1. Classify the various applications of Stack ADT. (U/C) 2. Convert an infix expression to postfix expression using Stack Data Structure. (Ap/C) 3. Compute the given postfix expression using Stack ADT. (Ap/C) 4. Demonstrate backtracking approach using Stack ADT with examples. (Ap/C)
  • 7. Four common stack applications are:  Reversing data,  Parsing,  Postponing and  Backtracking
  • 8.  Reversing - {1 2 3 4} becomes {4 3 2 1} Examples:  Reversing a list  Convert decimal to binary
  • 10. 91 16 7 5 3
  • 11. Pseudocode 1 read (number) 2 loop (number > 0) 1 set digit to number modulo 2 2 print (digit) 3 set number to quotient of number / 2 3 end loop Input:10 Output:0101 which is reverse of 1010STACK
  • 13.  Parsing is any logic that breaks an expression of data into independent pieces for further processing.  One common programming problem is unmatched parentheses in an algebraic expression.  When parentheses are unmatched, two types of errors can occur: the opening parenthesis can be missing or the closing parenthesis can be missing
  • 15. Solution using STACK:  Whenever we find an opening parentheses in a program, we push it into the stack.  When we find a closing parentheses, we pop its matching opening parentheses from the stack
  • 17.  A stack can be useful when the application requires that the use of data be postponed for a while. Examples:  Infix to postfix transformation  Postfix expression evaluation
  • 18. Formats for arithmetic expressions: 1. Infix expression  The operator comes between the operands.  Ex: A+B 2. Prefix expression  The operator comes before the operands.  Ex: +AB 3. Postfix expression  The operator comes after the operands.  Ex: AB+
  • 19. In the infix notation, we need to use parentheses to control the evaluation of the operators. We thus have an evaluation method that includes parentheses and two operator priority classes.  Priority 2 : * /  Priority 1 : + -  Priority 0 : (
  • 20. 1. Fully parenthesize the expression using any explicit parentheses and the arithmetic precedence. 2. Change all infix notations in each parenthesis to postfix notation, starting from the innermost expressions. Conversion to postfix notation is done by moving the operator to the location of the expression’s closing parenthesis. 3. Remove all parentheses.
  • 21. Infix expression  A+B*C  Step 1  (A+(B*C))  Step 2  (A+(BC*))  (A(BC*)+)  Step 3  ABC*+  Postfix expression
  • 22. Infix expression  (A+B)*C+D+E*F-G  Step 1  (((((A+B)*C)+D)+(E*F))-G)  Step 2  (((((AB+)*C)+D)+(EF*))-G)  (((((AB+)C*)+D)+(EF*))-G)  (((((AB+)C*)D+)+(EF*))-G)  (((((AB+)C*)D+)(EF*)+)-G)  (((((AB+)C*)D+)(EF*)+)G-)  Step 3  AB+C*D+EF*+G-  Postfix expression
  • 23.  Keep track of operators in the infix expression  If any operand is found, append it to the output expression  If any operator is found, push it into the stack such that:  If its priority is higher than the operator at the top of the stack, go ahead and push it onto the stack.  If the current operator’s priority is lower than or equal to that of the operator at the top of the stack than, then top operator is popped out of stack and placed in the output expression; thus the current operator becomes top operator.
  • 24.  Conversion of Infix to Postfix  Step 1: Consider the next element in the input.  Step 2: If it is operand, display it.  Step 3: If it is opening parenthesis, insert it on stack.  Step 4: If it is an operator, then If stack is empty, insert operator on stack.  If the top of stack is opening parenthesis, insert the operator on stack  If it has higher priority than the top of stack, insert the operator on stack.  Else, delete the operator from the stack and display it, repeat Step 4
  • 25.  Step 5: If it is a closing parenthesis, delete the operator from stack and display them until an opening parenthesis is encountered. Delete and discard the opening parenthesis.  Step 6: If there is more input, go to Step  Step 7: If there is no more input, delete the remaining operators to output.
  • 26.  Infix  A+B*C-D/E  Postfix ABC*+DE/-
  • 27. 3*3/(4-1)+6*2 expression into postfix form So, the Postfix Expression is 33*41-/62*+
  • 28.  Backtracking is another stack use found in applications such as computer gaming, decision analysis, and expert systems. Examples:  Goal Seeking  Eight Queens Problem
  • 60.  The postfix form of the expression (A+B)∗(C∗D-E)∗F/G is: A) AB+CD ∗ E−FG/∗∗ B) AB+CD ∗ E−F∗∗G/ C) AB+CD ∗ E−∗F∗G/ D) AB+CDE∗ −∗F∗G/
  • 61. A) AB+CD ∗ E−FG/∗∗
  • 62.  The postfix expression for the infix expression a+b*(c+d)/f+d*e is: A) ab+cd+*f/d+e* B) abcd+*f/+de*+ C) a*b+cd/f*de++ D) both (B) and (C)
  • 64.  Evaluate the postfix expression: 5 2 / 4 + 5 * 2 +
  • 67. Applications of stack Reversing data Reversing list Convert decimal to binary Parsing Unmatched Parentheses Postponement Infix to postfix conversion Evaluating postfix expression Backtracking Goal seeking Eight queens problem
  • 69.  Stack  Definition  Operations  Push  Pop  Stack top  Stack implementation using array  Stack implementation using Linked List