team 3
TRANSCRIPT
ASSIGNMENT PRESENTATION 1
STACK APPLICATION -PARENTHESES MATCHING
TEAM – 3• Amirthavarshyny.K (13MX02)• Darsini.R (13MX07)• Deepa.M (13MX08)• Hemashri.AVM (13MX15)• Kalaivani.M (13MX18)• Sindhu Bharathi.A (13MX44)
IntroductionOperations in stackStack Overflow & UnderflowPUSH AlgorithmPOP AlgorithmApplications of StackParentheses Checking or MatchingReferences
SYNOPSIS :
STACK :
It is an Abstract Data Type (ADT).
It is a linear data structure.
Follows LIFO (Last In First Out) data structure.
Only two operations are supported.
Real time examples:
a stack of plates, a stack of coins, batteries in
flashlight…
OPERATIONS:
PUSH:
- It is to insert an element into the
stack.
POP:
- It is to remove the element from the
stack.
STACK OVERFLOW :
If we insert an element into stack which
is FULL, the stack is OVERFLOW.
STACK UNDERFLOW :
If we delete an element from stack which
is EMPTY, the stack is UNDERFLOW.
PUSH an element
2
4
3
5
6
1
TOP = 6
item = 6
If we try to insert
another Element,
then n = 7.
Thus n = TOP.
This is STACK OVERFLOW.
A
POP an element
2
43 5
61TOP = 0
If we try to delete another element, then TOP < 0. This is STACK UNDERFLOW
PARENTHESES MATCHING:
It is one of the applications of stack
in which we check for correct matching
of the parentheses in the expression.
It checks for the correct nesting of the
parentheses in the expression.
ALGORITHM:
STEP 1 : Start
STEP 2 : Read the expression in
string format.
STEP 3 : Scan the expression from
left right.
STEP 4 : If any operator or operand is
encountered discard it.
STEP 5 : If left or open parentheses is
encountered PUSH it to the stack.
STEP 6 : If right or closed parentheses is
encountered POP top most element from
the stack.
STEP 7 : Continue the above three steps till
the sentinel character is encountered.
STEP 8 : If the stack is empty print
PARENTHESES MATCHED.
STEP 9 : Else PARENTHESES NOT
MATCHED.
STEP 10 : Stop.
{ E.g..World,[ ] })(This is anHello
Here the stack is EMPTY. Then , the result is
PARENTHESES MATCHED.
If the expression is like below,
{ E.g..World,[ ] })This is anHello
{ E.g..World,[ })(This is anHelloor
the stack will NOT be empty. Then, the result is PARENTHESES NOT MATCHED.
JUST TRY THIS:
Check the matching of the parentheses in the
following expressions.
{2*(A–B)]+(A/B)^2}
(A+B*(C–D)+F])
(((A+B)*C+D-E)/(F+G)-(H+J)*(K-L))/(M-
N)
REFERENCES: DATA STRUCTURES , ALGORITHMS AND APPLICATIONS IN C++ (2ND
EDITION) – Sartraj sahani
DATA STRUCTURES AND ALGORITHMS - CONCEPTS, TECHNIQUES AND
APPLICATIONS – G A Vijayalakshmi Pai.
PROGRAMMING AND DATA STRUCTURES – Ashok N. Kamthane.
http://
davesquared.net/2008/07/brackets-braces-parenthesis-and-other.h
tml
http://www.cs.uml.edu/~
msheldon/102/2011fall/notes/07_stacks/index.html
http://financelab.nctu.edu.tw/DataStructure/lec08.pdf
http://www.cise.ufl.edu/~sahni/cop3530/slides/lec126.pdf