SlideShare a Scribd company logo
2
Most read
4
Most read
8
Most read
STACK 
SUBMITTED BY: 
Archie Jamwal 
SUBMITTED TO: 
Mrs. Ruchi Gupta
DATA 
STRUCTURE 
LINEAR DATA 
STRUCTURE 
NON LINEAR 
DATA 
STRUCTURE 
ARRAY QUEUE STACK
What is Linear Data Structure 
In linear data structure, data is arranged 
in linear sequence. 
 Data items can be traversed in a single 
run. 
 In linear data structure elements are 
accessed or placed in contiguous(together 
in sequence) memory location.
WHAT Is 
 A stack is called a last-in-first-out (LIFO) 
collection. This means that the last thing 
we added (pushed) is the first thing that 
gets pulled (popped) off. 
 A stack is a sequence of items that are 
accessible at only one end of the sequence.
EXAMPLES OF STACK:
Operations that can be performed 
on STACK: 
 PUSH. 
 POP.
PUSH : It is used to insert items into the stack. 
POP: It is used to delete items from stack. 
TOP: It represents the current location of data 
in stack.
ALGORITHM OF INSERTION IN 
STACK: (PUSH) 
1. Insertion(a,top,item,max) 
2. If top=max then 
print ‘STACK OVERFLOW’ 
exit 
else 
3. top=top+1 
end if 
4. a[top]=item 
5. Exit
ALGORITHM OF DELETION IN 
STACK: (POP) 
1. Deletion(a,top,item) 
2. If top=0 then 
print ‘STACK UNDERFLOW’ 
exit 
else 
3. item=a[top] 
end if 
4. top=top-1 
5. Exit
ALGORITHM OF DISPLAY IN 
STACK: 
1.Display(top,i,a[i]) 
2.If top=0 then 
Print ‘STACK EMPTY’ 
Exit 
Else 
3.For i=top to 0 
Print a[i] 
End for 
4.exit
APPLICATIONS OF STACKS ARE: 
I. Reversing Strings: 
• A simple application of stack is reversing strings. 
To reverse a string , the characters of string are 
pushed onto the stack one by one as the string 
is read from left to right. 
• Once all the characters 
of string are pushed onto stack, they are 
popped one by one. Since the character last 
pushed in comes out first, subsequent pop 
operation results in the reversal of the string.
For example: 
To reverse the string ‘REVERSE’ the string is 
read from left to right and its characters are 
pushed . LIKE: 
onto a stack.
II. Checking the validity of an expression 
containing nested parenthesis: 
• Stacks are also used to check whether a given 
arithmetic expressions containing nested 
parenthesis is properly parenthesized. 
• The program for checking the validity of an 
expression verifies that for each left parenthesis 
braces or bracket ,there is a corresponding 
closing symbol and symbols are appropriately 
nested.
For example: 
VALID INPUTS INVALID INPUTS 
{ } 
{ ( } 
( { [ ] } ) 
( [ ( ( ) ] ) 
{ [ ] ( ) } 
{ } [ ] ) 
[ { ( { } [ ] ( { 
[ { ) } ( ] } ] 
})}]
III. Evaluating arithmetic expressions: 
INFIX notation: 
The general way of writing arithmetic 
expressions is known as infix notation. 
e.g, (a+b) 
PREFIX notation: 
e.g, +AB 
POSTFIX notation: 
e.g: AB+
Conversion of INFIX to POSTFIX conversion: 
Example: 2+(4-1)*3 step1 
2+41-*3 step2 
2+41-3* step3 
241-3*+ step4
CURRENT 
SYMBOL 
ACTION 
PERFORMED 
STACK STATUS POSTFIX 
EXPRESSION 
( PUSH C C 2 
2 2 
+ PUSH + (+ 2 
( PUSH ( (+( 24 
4 24 
- PUSH - (+(- 241 
1 POP 241- 
) (+ 241- 
* PUSH * (+* 241- 
3 241-3 
POP * 241-3* 
POP + 241-3*+ 
) 
CONVERSION OF INFIX INTO POSTFIX 
2+(4-1)*3 into 241-3*+
THANK YOU 

More Related Content

PPTX
stack & queue
PPTX
Queue ppt
PPTX
Stacks IN DATA STRUCTURES
PPTX
Presentation on queue
PPTX
linked list in data structure
PDF
PPT
PPTX
Linked list
stack & queue
Queue ppt
Stacks IN DATA STRUCTURES
Presentation on queue
linked list in data structure
Linked list

What's hot (20)

PPTX
Array ppt
PPTX
Graph in data structure
PPTX
Queue in Data Structure
PPTX
queue & its applications
PPT
Operator Overloading
PPT
1.1 binary tree
PPTX
Data structure - Graph
PPTX
Functions in python slide share
PPTX
Queue - Data Structure - Notes
PPTX
Array Introduction One-dimensional array Multidimensional array
PPTX
List in Python
PPTX
Presentation on array
PPT
PDF
Applications of stack
PPTX
Tree - Data Structure
PPTX
Doubly Linked List
PPTX
Binary Search Tree
PPTX
Deque and its applications
PPTX
AVL Tree in Data Structure
Array ppt
Graph in data structure
Queue in Data Structure
queue & its applications
Operator Overloading
1.1 binary tree
Data structure - Graph
Functions in python slide share
Queue - Data Structure - Notes
Array Introduction One-dimensional array Multidimensional array
List in Python
Presentation on array
Applications of stack
Tree - Data Structure
Doubly Linked List
Binary Search Tree
Deque and its applications
AVL Tree in Data Structure
Ad

Similar to STACKS IN DATASTRUCTURE (20)

PPTX
dsppt-141121224848-conversion01 (1).pptx
PPTX
Stack_Data_Structure.pptx
PPTX
Stacks Data structure.pptx
PPTX
Project on stack Data structure
PPTX
PPTX
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
PPTX
Stacks and queues using aaray line .pptx
PPTX
Stacks in DATA STRUCTURE
PPSX
PPT
Stack in Data Structure
PPT
Data Structure and Algorithms Stacks
PPTX
DATA STRUCTURE - STACK
PPT
Unit 3 stack
PPT
Chapter 6 ds
PPTX
Stack data structure
PDF
Data Structures And Algorithms(stacks queues)
PPT
Stack Operation In Data Structure
PPTX
Stacks
PPT
week 7,8,10,11 alll files included from .ppt
PPTX
DS-UNIT 3 FINAL.pptx
dsppt-141121224848-conversion01 (1).pptx
Stack_Data_Structure.pptx
Stacks Data structure.pptx
Project on stack Data structure
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
Stacks and queues using aaray line .pptx
Stacks in DATA STRUCTURE
Stack in Data Structure
Data Structure and Algorithms Stacks
DATA STRUCTURE - STACK
Unit 3 stack
Chapter 6 ds
Stack data structure
Data Structures And Algorithms(stacks queues)
Stack Operation In Data Structure
Stacks
week 7,8,10,11 alll files included from .ppt
DS-UNIT 3 FINAL.pptx
Ad

Recently uploaded (20)

PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
01-Introduction-to-Information-Management.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Open folder Downloads.pdf yes yes ges yes
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
Cell Structure & Organelles in detailed.
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
01-Introduction-to-Information-Management.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Abdominal Access Techniques with Prof. Dr. R K Mishra
Open folder Downloads.pdf yes yes ges yes
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
TR - Agricultural Crops Production NC III.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Cell Structure & Organelles in detailed.
The Final Stretch: How to Release a Game and Not Die in the Process.
Cardiovascular Pharmacology for pharmacy students.pptx
Microbial diseases, their pathogenesis and prophylaxis

STACKS IN DATASTRUCTURE

  • 1. STACK SUBMITTED BY: Archie Jamwal SUBMITTED TO: Mrs. Ruchi Gupta
  • 2. DATA STRUCTURE LINEAR DATA STRUCTURE NON LINEAR DATA STRUCTURE ARRAY QUEUE STACK
  • 3. What is Linear Data Structure In linear data structure, data is arranged in linear sequence.  Data items can be traversed in a single run.  In linear data structure elements are accessed or placed in contiguous(together in sequence) memory location.
  • 4. WHAT Is  A stack is called a last-in-first-out (LIFO) collection. This means that the last thing we added (pushed) is the first thing that gets pulled (popped) off.  A stack is a sequence of items that are accessible at only one end of the sequence.
  • 6. Operations that can be performed on STACK:  PUSH.  POP.
  • 7. PUSH : It is used to insert items into the stack. POP: It is used to delete items from stack. TOP: It represents the current location of data in stack.
  • 8. ALGORITHM OF INSERTION IN STACK: (PUSH) 1. Insertion(a,top,item,max) 2. If top=max then print ‘STACK OVERFLOW’ exit else 3. top=top+1 end if 4. a[top]=item 5. Exit
  • 9. ALGORITHM OF DELETION IN STACK: (POP) 1. Deletion(a,top,item) 2. If top=0 then print ‘STACK UNDERFLOW’ exit else 3. item=a[top] end if 4. top=top-1 5. Exit
  • 10. ALGORITHM OF DISPLAY IN STACK: 1.Display(top,i,a[i]) 2.If top=0 then Print ‘STACK EMPTY’ Exit Else 3.For i=top to 0 Print a[i] End for 4.exit
  • 11. APPLICATIONS OF STACKS ARE: I. Reversing Strings: • A simple application of stack is reversing strings. To reverse a string , the characters of string are pushed onto the stack one by one as the string is read from left to right. • Once all the characters of string are pushed onto stack, they are popped one by one. Since the character last pushed in comes out first, subsequent pop operation results in the reversal of the string.
  • 12. For example: To reverse the string ‘REVERSE’ the string is read from left to right and its characters are pushed . LIKE: onto a stack.
  • 13. II. Checking the validity of an expression containing nested parenthesis: • Stacks are also used to check whether a given arithmetic expressions containing nested parenthesis is properly parenthesized. • The program for checking the validity of an expression verifies that for each left parenthesis braces or bracket ,there is a corresponding closing symbol and symbols are appropriately nested.
  • 14. For example: VALID INPUTS INVALID INPUTS { } { ( } ( { [ ] } ) ( [ ( ( ) ] ) { [ ] ( ) } { } [ ] ) [ { ( { } [ ] ( { [ { ) } ( ] } ] })}]
  • 15. III. Evaluating arithmetic expressions: INFIX notation: The general way of writing arithmetic expressions is known as infix notation. e.g, (a+b) PREFIX notation: e.g, +AB POSTFIX notation: e.g: AB+
  • 16. Conversion of INFIX to POSTFIX conversion: Example: 2+(4-1)*3 step1 2+41-*3 step2 2+41-3* step3 241-3*+ step4
  • 17. CURRENT SYMBOL ACTION PERFORMED STACK STATUS POSTFIX EXPRESSION ( PUSH C C 2 2 2 + PUSH + (+ 2 ( PUSH ( (+( 24 4 24 - PUSH - (+(- 241 1 POP 241- ) (+ 241- * PUSH * (+* 241- 3 241-3 POP * 241-3* POP + 241-3*+ ) CONVERSION OF INFIX INTO POSTFIX 2+(4-1)*3 into 241-3*+