SlideShare a Scribd company logo
The Stack
• A stack is one of the most important and useful non primitive linear data structure in computer
science.
• As all the deletion and insertion in a stack is done from top of the stack, the last added element will
be the first to be removed from the stack.
• This is the reason why the stack is also called Last In – First Out (LIFO) type of list.
• It is interesting to notice that the most frequently accessible element in the stack are the most top
elements, while the least accessible elements located at the bottom of the stack.
• In our everyday life, we come across many examples of stacks shown in the figure below
Consider a stack of books on a table. We can easily put a new book on the top of the stack,
and similarly, we can easily remove the topmost book as compared to the books lying in-
between or at the bottom positions. In the same way, only the topmost element of a stack
can be accessed while direct access of other intermediate positions is not feasible. Elements
may be added to or removed. from only one end, called the top of a stack.
Stack can be implemented in two ways:
1. Static implementation (using arrays)
2. Dynamic implementation (using pointers)
Static implementation uses arrays to create stack. Static implementation using
arrays is a very simple technique but is not a flexible way, as the size of the stack
has to be declared during the program design, because after that, the size cannot
be varied.
The insertion (or addition) operation is referred to as push, and the deletion (or
remove) operation as pop. A stack is said to be empty or underflow, if the stack
contains no elements. At this point the top of the stack is present at the bottom of
the stack.
And it is overflow when the stack becomes full, i.e., no other elements can be
pushed onto the stack. At this point the top pointer is at the highest location of
the stack.
Operations Performed on Stack
There are two basic operations that can be performed on the stack,
these are:
1. PUSH: is the process of adding a new element to the top of the stack.
As a new element pushed to the stack, top will be incremented by one
and denote to the added element. Adding a new element when the
stack is full is called stack overflow.
2. POP: is the process of deleting an element from the top of the stack.
After every pop operation, the top is decremented by one. If there are
no elements in the stack and pop operation is performed, the result is
called stack underflow.
Stack Terminology:
1. Size: this term refers to the maximum size of the stack or the number
of possibly added elements.
2. TOP: this term refers to the top of the stack. It is a stack pointer used
to check overflow and under flow conditions. The initial value of TOP
is -1 when the stack is empty.
3. Stack underflow: is the situation when the stack contains no
elements. At this point the top of the stack points to the stack bottom.
4. Stack overflow: is the situation when the stack is full and no more
elements can be added. At this point the top of the stack points to the
highest location in the stack.
Example of push and pop operations.
It is an ordered collection of items
into which new data items may be
added/inserted and from which
items may be deleted at only one
end, called the top of the stack.
Exercise:
Example: What is the obtained string after performing the following sequence of
push and pop:
PUSH(A), PUSH(B), POP, PUSH(C), POP, PUSH(D), PUSH(E), POP,
POP, POP
Solution:
So, the obtained string is (BCEDA)
Example: What is the obtained number after performing the following sequence of
push and pop:
PUSH(1), POP, PUSH(2), PUSH(3), POP, PUSH(4), POP, PUSH(5), POP,
POP
Solution:
So the obtained number is (13452).
Example: What is the required sequence of push and pop to obtain the string
(CBDAE)
from the initial input (ABCDE).
Solution:

More Related Content

Similar to The Stack (Data Structccccccccccccccccccc (20)

PPTX
STACK.pptx
rupam100
 
PPTX
STACK.pptx
Dr.Shweta
 
PPT
Stack a Data Structure
ForwardBlog Enewzletter
 
PPTX
The presentation on stack data structure
gaurav77712
 
PDF
Stack
Amrutha Rajan
 
PDF
Stack push pop
A. S. M. Shafi
 
PPT
The Stack in data structures .ppt
donemoremaregere376
 
PPTX
Unit 3 stack
Dabbal Singh Mahara
 
PPTX
Data structure Stack
Praveen Vishwakarma
 
PPTX
Data structure by Digvijay
Digvijay Singh Karakoti
 
PPTX
stack_ppt_DSA(sudipta samanta).pptx push,pop,peek operation
sudiptasamanta86493
 
PPT
stack, opeartions on stack, applications of stack
Minakshee Patil
 
PPTX
Stacks in Data Structure
Lovely Professional University
 
PPTX
My lecture stack_queue_operation
Senthil Kumar
 
PPTX
STACK_IN_DATA STRUCTURE AND ALGORITHMS.pptx
bwubca22582
 
PPSX
Stacks fundamentals
greatqadirgee4u
 
PPT
Lecture5
Muhammad Zubair
 
PPTX
Stack and its operations
V.V.Vanniaperumal College for Women
 
PPTX
Data Structure ARRAY REPRESENTATION OF STACKS
Anil Yadav
 
STACK.pptx
rupam100
 
STACK.pptx
Dr.Shweta
 
Stack a Data Structure
ForwardBlog Enewzletter
 
The presentation on stack data structure
gaurav77712
 
Stack push pop
A. S. M. Shafi
 
The Stack in data structures .ppt
donemoremaregere376
 
Unit 3 stack
Dabbal Singh Mahara
 
Data structure Stack
Praveen Vishwakarma
 
Data structure by Digvijay
Digvijay Singh Karakoti
 
stack_ppt_DSA(sudipta samanta).pptx push,pop,peek operation
sudiptasamanta86493
 
stack, opeartions on stack, applications of stack
Minakshee Patil
 
Stacks in Data Structure
Lovely Professional University
 
My lecture stack_queue_operation
Senthil Kumar
 
STACK_IN_DATA STRUCTURE AND ALGORITHMS.pptx
bwubca22582
 
Stacks fundamentals
greatqadirgee4u
 
Lecture5
Muhammad Zubair
 
Stack and its operations
V.V.Vanniaperumal College for Women
 
Data Structure ARRAY REPRESENTATION OF STACKS
Anil Yadav
 

Recently uploaded (20)

PDF
Mock Examination 2025.pdf o level all subjects
kharrotikhan
 
PPTX
Mastering-Communication-Your-Essential-Skills-Toolkit.pptx.pptx
rahulkesharwani642
 
PDF
Left Holding the Bag sequence 3 Storyboard by Mark G.
MarkGalez
 
PPTX
Presentation saif 8.pptx Flowers bloom though storms may stay, They find thei...
gemarking678
 
PDF
Fortinet FCSS_LED_AR-7.6 Certification: Study Hacks With Exam Questions
sabrina pinto
 
PPTX
FSS seminar-cours-work the future of material surfaces.pptx
sanjaychief112
 
PPTX
Presentation.pptxjjjnjnnnnnnnnnnnnnnnnnnnn
simajameel01
 
DOCX
The Basics of British Sign Language.docx
biloguard123
 
PPTX
Capstone Professional Portfolio Melissa Alice
malice926
 
DOCX
(14-5) Bo-15-De-luyen-thi-vao-10-Ha-Noi-25-26.docx
27QuynNhnChu
 
PDF
The Rise of Modern Entrepreneurs_ A New Style of Leadership by Doug Pitassi.pdf
Doug Pitassi
 
PPTX
Role & Etiquette of a Medical Representative – Do’s & Don’ts Inside the Docto...
Sujoy Dasgupta
 
PPTX
introduction to python in detail including .pptx
urvashipundir04
 
PPTX
FARZ ACADEMY MRCP EXAM PREPARATION-GUIDE & TIPS.pptx
dawnmarketingmaveric
 
PDF
Left Holding the Bag sequence 1 storyboard by Mark G.
MarkGalez
 
PPTX
Campus Deck_All catrerr prospect park on the best
VaishnaviChitale
 
PPTX
tech vs soft skill .pptxhgdvnhygnuufcbnbg
spnr2427
 
PDF
Meatball of Canyon Valley sequence 2 storyboard by Mark G.
MarkGalez
 
PDF
PowerPoint Presentation -- Larry G -- 2021 -- 218df4ebe0bc5607d6bfcf49fd21eda...
Adeel452922
 
PPTX
Quattro Resourcing - Recruitment that works for you
neilsimon919
 
Mock Examination 2025.pdf o level all subjects
kharrotikhan
 
Mastering-Communication-Your-Essential-Skills-Toolkit.pptx.pptx
rahulkesharwani642
 
Left Holding the Bag sequence 3 Storyboard by Mark G.
MarkGalez
 
Presentation saif 8.pptx Flowers bloom though storms may stay, They find thei...
gemarking678
 
Fortinet FCSS_LED_AR-7.6 Certification: Study Hacks With Exam Questions
sabrina pinto
 
FSS seminar-cours-work the future of material surfaces.pptx
sanjaychief112
 
Presentation.pptxjjjnjnnnnnnnnnnnnnnnnnnnn
simajameel01
 
The Basics of British Sign Language.docx
biloguard123
 
Capstone Professional Portfolio Melissa Alice
malice926
 
(14-5) Bo-15-De-luyen-thi-vao-10-Ha-Noi-25-26.docx
27QuynNhnChu
 
The Rise of Modern Entrepreneurs_ A New Style of Leadership by Doug Pitassi.pdf
Doug Pitassi
 
Role & Etiquette of a Medical Representative – Do’s & Don’ts Inside the Docto...
Sujoy Dasgupta
 
introduction to python in detail including .pptx
urvashipundir04
 
FARZ ACADEMY MRCP EXAM PREPARATION-GUIDE & TIPS.pptx
dawnmarketingmaveric
 
Left Holding the Bag sequence 1 storyboard by Mark G.
MarkGalez
 
Campus Deck_All catrerr prospect park on the best
VaishnaviChitale
 
tech vs soft skill .pptxhgdvnhygnuufcbnbg
spnr2427
 
Meatball of Canyon Valley sequence 2 storyboard by Mark G.
MarkGalez
 
PowerPoint Presentation -- Larry G -- 2021 -- 218df4ebe0bc5607d6bfcf49fd21eda...
Adeel452922
 
Quattro Resourcing - Recruitment that works for you
neilsimon919
 
Ad

The Stack (Data Structccccccccccccccccccc

  • 1. The Stack • A stack is one of the most important and useful non primitive linear data structure in computer science. • As all the deletion and insertion in a stack is done from top of the stack, the last added element will be the first to be removed from the stack. • This is the reason why the stack is also called Last In – First Out (LIFO) type of list. • It is interesting to notice that the most frequently accessible element in the stack are the most top elements, while the least accessible elements located at the bottom of the stack. • In our everyday life, we come across many examples of stacks shown in the figure below
  • 2. Consider a stack of books on a table. We can easily put a new book on the top of the stack, and similarly, we can easily remove the topmost book as compared to the books lying in- between or at the bottom positions. In the same way, only the topmost element of a stack can be accessed while direct access of other intermediate positions is not feasible. Elements may be added to or removed. from only one end, called the top of a stack.
  • 3. Stack can be implemented in two ways: 1. Static implementation (using arrays) 2. Dynamic implementation (using pointers) Static implementation uses arrays to create stack. Static implementation using arrays is a very simple technique but is not a flexible way, as the size of the stack has to be declared during the program design, because after that, the size cannot be varied. The insertion (or addition) operation is referred to as push, and the deletion (or remove) operation as pop. A stack is said to be empty or underflow, if the stack contains no elements. At this point the top of the stack is present at the bottom of the stack. And it is overflow when the stack becomes full, i.e., no other elements can be pushed onto the stack. At this point the top pointer is at the highest location of the stack.
  • 4. Operations Performed on Stack There are two basic operations that can be performed on the stack, these are: 1. PUSH: is the process of adding a new element to the top of the stack. As a new element pushed to the stack, top will be incremented by one and denote to the added element. Adding a new element when the stack is full is called stack overflow. 2. POP: is the process of deleting an element from the top of the stack. After every pop operation, the top is decremented by one. If there are no elements in the stack and pop operation is performed, the result is called stack underflow.
  • 5. Stack Terminology: 1. Size: this term refers to the maximum size of the stack or the number of possibly added elements. 2. TOP: this term refers to the top of the stack. It is a stack pointer used to check overflow and under flow conditions. The initial value of TOP is -1 when the stack is empty. 3. Stack underflow: is the situation when the stack contains no elements. At this point the top of the stack points to the stack bottom. 4. Stack overflow: is the situation when the stack is full and no more elements can be added. At this point the top of the stack points to the highest location in the stack.
  • 6. Example of push and pop operations.
  • 7. It is an ordered collection of items into which new data items may be added/inserted and from which items may be deleted at only one end, called the top of the stack.
  • 9. Example: What is the obtained string after performing the following sequence of push and pop: PUSH(A), PUSH(B), POP, PUSH(C), POP, PUSH(D), PUSH(E), POP, POP, POP Solution: So, the obtained string is (BCEDA)
  • 10. Example: What is the obtained number after performing the following sequence of push and pop: PUSH(1), POP, PUSH(2), PUSH(3), POP, PUSH(4), POP, PUSH(5), POP, POP Solution: So the obtained number is (13452).
  • 11. Example: What is the required sequence of push and pop to obtain the string (CBDAE) from the initial input (ABCDE). Solution: