The document discusses a team presentation on using a stack data structure to check for matching parentheses in an expression. It defines what a stack is, the push and pop operations, and provides pseudocode for algorithms to add and remove elements from a stack. It then explains how to use a stack to check an expression by pushing opening parentheses and popping closing ones, identifying whether the stack is empty after as a way to check matching. Examples of expressions are provided to demonstrate the algorithm.
2. SYNOPSIS :
ï‚— Introduction
ï‚— Operations in stack
ï‚— Stack Overflow & Underflow
ï‚— PUSH Algorithm
ï‚— POP Algorithm
ï‚— Applications of Stack
ï‚— Parentheses Checking or Matching
ï‚— References
3. 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…
4. OPERATIONS:
ï‚— PUSH:
- It is to insert an element into the
stack.
ï‚— POP:
- It is to remove the element from the
stack.
5. 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.
27. 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.
28. ALGORITHM:
STEP 1 : Start
STEP 2 : Read the expression in
string format.
STEP 3 : Scan the expression from
left ïƒ right.
29. 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.
30. 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.
45. Here the stack is EMPTY. Then , the
result is
PARENTHESES MATCHED.
46. If the expression is like below,
or
the stack will NOT be empty. Then,
the result is PARENTHESES NOT
MATCHED.
47. 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)
48. 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.
html
ï‚— 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