SlideShare a Scribd company logo
DATA STRUCTURES
STACK OPERATIONS
- Dr. Gopika S
Asst Professor
Department of Computer Science
Kristu Jayanti College
Conceptual View of a Stack
bottom
of stack
(old) top
of stack
New object is added as the
new top element of the stack
Adding an element
new
top
bottom
Stack Operations Dr. Gopika S, KJC, Bengaluru
Conceptual View of a Stack
Object is removed from the top
of the stack
Removing an element
top
bottom
new
top
bottom
Stack Operations
Dr. Gopika S, KJC, Bengaluru
Uses of Stacks in Computing
Useful for any kind of problem involving
LIFO data
• Backtracking: in puzzles and games
• Browsers
• To keep track of pages visited in a browser
tab
Stack Operations
Dr. Gopika S, KJC, Bengaluru
Uses of Stacks in Computing
• Word Processors, editors
• To check expressions or strings of text for matching
parentheses / brackets
e.g. if (a == b)
{ c = (d + e) * f;
}
• To implement undo operations
• Keeps track of the most recent operations
• Markup languages (e.g. HTML, XML): have
formatting information (tags) as well as raw text
• To check for matching tags
e.g. <HEAD>
<TITLE>Computer Science 1027a</TITLE>
</HEAD>
Stack Operations
Dr. Gopika S, KJC, Bengaluru
Uses of Stacks in Computing
• Stack Calculators
• To convert an infix expression to postfix,
to make evaluation easier (more on this later)
Infix expression: a * b + c
Postfix expression: a b * c +
• To evaluate postfix expressions (ditto)
• Compilers
• To convert infix expressions to postfix, to
make translation of a high-level language
such as Java or C to a lower level
language easier
Stack Operations
Dr. Gopika S, KJC, Bengaluru
Uses of Stacks in Computing
• Call stack (Runtime stack)
• Used by runtime system when methods are invoked, for
method call / return processing (more on this later)
• e.g. main calls method1
method1 calls method 2
method 2 returns …
• Holds “call frame” containing local variables, parameters,
etc.
• Why is a stack structure used for this?
Stack Operations
Dr. Gopika S, KJC, Bengaluru
Operations on a Collection
• Every collection has a set of operations that
define how we interact with it, for example:
• Add elements
• Remove elements
• Determine if the collection is empty
• Determine the collection's size
Stack Operations
Dr. Gopika S, KJC, Bengaluru
Stack Operations
• push: add an element at the top of the stack
• pop: remove the element at the top of the stack
• peek: examine the element at the top of the stack
• It is not legal to access any element other than the
one that is at the top of the stack!
Stack Operations
Dr. Gopika S, KJC, Bengaluru
Operations on a Stack
Operation Description
push Adds an element to the top of the stack
pop Removes an element from the top of the stack
peek Examines the element at the top of the stack
isEmpty Determines whether the stack is empty
size Determines the number of elements in the stack
toString Returns a string representation of the stack
Stack Operations
Dr. Gopika S, KJC, Bengaluru

More Related Content

PPTX
Wrokflow programming and provenance query model
Rayhan Ferdous
 
PDF
Link List
Budditha Hettige
 
PPTX
Queue Data Structure
Afaq Mansoor Khan
 
PDF
Sorting
Budditha Hettige
 
DOCX
Best,worst,average case .17581556 045
university of Gujrat, pakistan
 
PPTX
9 big o-notation
irdginfo
 
PPTX
Analysis of algorithms
iqbalphy1
 
PPTX
Data structures and algorithms
Julie Iskander
 
Wrokflow programming and provenance query model
Rayhan Ferdous
 
Link List
Budditha Hettige
 
Queue Data Structure
Afaq Mansoor Khan
 
Best,worst,average case .17581556 045
university of Gujrat, pakistan
 
9 big o-notation
irdginfo
 
Analysis of algorithms
iqbalphy1
 
Data structures and algorithms
Julie Iskander
 

What's hot (20)

PPT
Sorting Algorithms
multimedia9
 
PPTX
Document clustering for forensic analysis an approach for improving compute...
Madan Golla
 
PPTX
Stack Data Structure
Rabin BK
 
PPTX
An Introduction To Python - Lists, Part 1
Blue Elephant Consulting
 
PPTX
Stack Data structure
B Liyanage Asanka
 
PDF
Algorithm and Data Structure - Queue
AndiNurkholis1
 
PDF
Week 2 - Data Structures and Algorithms
Ferdin Joe John Joseph PhD
 
PPTX
Big O Notation
Marcello Missiroli
 
PDF
Algorithm and Data Structure - Stack
AndiNurkholis1
 
PDF
Data Structures and Algorithm - Week 9 - Search Algorithms
Ferdin Joe John Joseph PhD
 
PPT
Searching algorithms
Trupti Agrawal
 
PDF
Week 1 - Data Structures and Algorithms
Ferdin Joe John Joseph PhD
 
PPTX
Basic of Data Structure - Data Structure - Notes
Omprakash Chauhan
 
PDF
A software agent controlling 2 robot arms in co-operating concurrent tasks
RuleML
 
PPTX
Slide 1.-datastructure
Minhaz Leo
 
PPTX
Implementation of queue using singly and doubly linked list.
central university of bihar
 
PPT
Stacks in algorithems & data structure
faran nawaz
 
PPTX
Ppt presentation of queues
Buxoo Abdullah
 
PDF
Data Structures 01
Budditha Hettige
 
PPTX
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
Jannat Ruma
 
Sorting Algorithms
multimedia9
 
Document clustering for forensic analysis an approach for improving compute...
Madan Golla
 
Stack Data Structure
Rabin BK
 
An Introduction To Python - Lists, Part 1
Blue Elephant Consulting
 
Stack Data structure
B Liyanage Asanka
 
Algorithm and Data Structure - Queue
AndiNurkholis1
 
Week 2 - Data Structures and Algorithms
Ferdin Joe John Joseph PhD
 
Big O Notation
Marcello Missiroli
 
Algorithm and Data Structure - Stack
AndiNurkholis1
 
Data Structures and Algorithm - Week 9 - Search Algorithms
Ferdin Joe John Joseph PhD
 
Searching algorithms
Trupti Agrawal
 
Week 1 - Data Structures and Algorithms
Ferdin Joe John Joseph PhD
 
Basic of Data Structure - Data Structure - Notes
Omprakash Chauhan
 
A software agent controlling 2 robot arms in co-operating concurrent tasks
RuleML
 
Slide 1.-datastructure
Minhaz Leo
 
Implementation of queue using singly and doubly linked list.
central university of bihar
 
Stacks in algorithems & data structure
faran nawaz
 
Ppt presentation of queues
Buxoo Abdullah
 
Data Structures 01
Budditha Hettige
 
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
Jannat Ruma
 
Ad

Similar to Data Structures: Stack Operations (20)

PDF
PostgreSQL 9.4, 9.5 and Beyond @ COSCUP 2015 Taipei
Satoshi Nagayasu
 
PDF
Data Structures and Algorithm - Week 3 - Stacks and Queues
Ferdin Joe John Joseph PhD
 
PPT
Data Structures
Dr.Umadevi V
 
PPTX
stack.pptx
mayankKatiyar17
 
PPTX
CD3291 2.5 stack.pptx
mareeswari15
 
PDF
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
Edureka!
 
PDF
sweetu stacks.pdf
mohit476551
 
PDF
9 python data structure-2
Prof. Dr. K. Adisesha
 
PPTX
Unit I-Data structures stack & Queue
DrkhanchanaR
 
PPTX
Data Structure - Stacks
Sampad Kar
 
PPT
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
SnehilKeshari
 
PDF
Building a Complex, Real-Time Data Management Application
Jonathan Katz
 
PPTX
Javascript stack
Samuel Santos
 
PPT
linked list in c++
YaminiLakshmi Meduri
 
PPTX
stack_presentaton_HUSNAIN[2].pojklklklptx
HusnainNaqvi2
 
PDF
The Art of Database Experiments – PostgresConf Silicon Valley 2018 / San Jose
Nikolay Samokhvalov
 
PPTX
data structures power point presentation
cselt2403
 
PPTX
STACK.pptx
Dr.Shweta
 
PPTX
Stacks and Queue,Concept of Stack,LIFO,Fifo,
shaikhdaniyal8603
 
PostgreSQL 9.4, 9.5 and Beyond @ COSCUP 2015 Taipei
Satoshi Nagayasu
 
Data Structures and Algorithm - Week 3 - Stacks and Queues
Ferdin Joe John Joseph PhD
 
Data Structures
Dr.Umadevi V
 
stack.pptx
mayankKatiyar17
 
CD3291 2.5 stack.pptx
mareeswari15
 
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
Edureka!
 
sweetu stacks.pdf
mohit476551
 
9 python data structure-2
Prof. Dr. K. Adisesha
 
Unit I-Data structures stack & Queue
DrkhanchanaR
 
Data Structure - Stacks
Sampad Kar
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
SnehilKeshari
 
Building a Complex, Real-Time Data Management Application
Jonathan Katz
 
Javascript stack
Samuel Santos
 
linked list in c++
YaminiLakshmi Meduri
 
stack_presentaton_HUSNAIN[2].pojklklklptx
HusnainNaqvi2
 
The Art of Database Experiments – PostgresConf Silicon Valley 2018 / San Jose
Nikolay Samokhvalov
 
data structures power point presentation
cselt2403
 
STACK.pptx
Dr.Shweta
 
Stacks and Queue,Concept of Stack,LIFO,Fifo,
shaikhdaniyal8603
 
Ad

More from GopikaS12 (10)

PPTX
History and Introduction to LINUX .pptx
GopikaS12
 
PPTX
Memory management concepts in operating system
GopikaS12
 
PPTX
Conditional control statements explains the programming constructs
GopikaS12
 
PPTX
Deadlock _Classic problems.pptx
GopikaS12
 
PPTX
Introduction to Tree .pptx
GopikaS12
 
PPTX
C Programming language - introduction
GopikaS12
 
PPTX
C formatted and unformatted input and output constructs
GopikaS12
 
PPTX
Heap creation from elements - Step by step Approach
GopikaS12
 
PPT
Net content in computer architecture
GopikaS12
 
PPTX
It unit 1
GopikaS12
 
History and Introduction to LINUX .pptx
GopikaS12
 
Memory management concepts in operating system
GopikaS12
 
Conditional control statements explains the programming constructs
GopikaS12
 
Deadlock _Classic problems.pptx
GopikaS12
 
Introduction to Tree .pptx
GopikaS12
 
C Programming language - introduction
GopikaS12
 
C formatted and unformatted input and output constructs
GopikaS12
 
Heap creation from elements - Step by step Approach
GopikaS12
 
Net content in computer architecture
GopikaS12
 
It unit 1
GopikaS12
 

Recently uploaded (20)

PPTX
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
Introduction to Data Science: data science process
ShivarkarSandip
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PPTX
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
PDF
flutter Launcher Icons, Splash Screens & Fonts
Ahmed Mohamed
 
PPT
SCOPE_~1- technology of green house and poyhouse
bala464780
 
PDF
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
PPT
Ppt for engineering students application on field effect
lakshmi.ec
 
PPTX
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
PDF
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PDF
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
PPTX
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
PDF
dse_final_merit_2025_26 gtgfffffcjjjuuyy
rushabhjain127
 
PPTX
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
PDF
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
PPTX
Information Retrieval and Extraction - Module 7
premSankar19
 
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Introduction to Data Science: data science process
ShivarkarSandip
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
Inventory management chapter in automation and robotics.
atisht0104
 
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
flutter Launcher Icons, Splash Screens & Fonts
Ahmed Mohamed
 
SCOPE_~1- technology of green house and poyhouse
bala464780
 
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
Ppt for engineering students application on field effect
lakshmi.ec
 
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
dse_final_merit_2025_26 gtgfffffcjjjuuyy
rushabhjain127
 
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
Information Retrieval and Extraction - Module 7
premSankar19
 

Data Structures: Stack Operations

  • 1. DATA STRUCTURES STACK OPERATIONS - Dr. Gopika S Asst Professor Department of Computer Science Kristu Jayanti College
  • 2. Conceptual View of a Stack bottom of stack (old) top of stack New object is added as the new top element of the stack Adding an element new top bottom Stack Operations Dr. Gopika S, KJC, Bengaluru
  • 3. Conceptual View of a Stack Object is removed from the top of the stack Removing an element top bottom new top bottom Stack Operations Dr. Gopika S, KJC, Bengaluru
  • 4. Uses of Stacks in Computing Useful for any kind of problem involving LIFO data • Backtracking: in puzzles and games • Browsers • To keep track of pages visited in a browser tab Stack Operations Dr. Gopika S, KJC, Bengaluru
  • 5. Uses of Stacks in Computing • Word Processors, editors • To check expressions or strings of text for matching parentheses / brackets e.g. if (a == b) { c = (d + e) * f; } • To implement undo operations • Keeps track of the most recent operations • Markup languages (e.g. HTML, XML): have formatting information (tags) as well as raw text • To check for matching tags e.g. <HEAD> <TITLE>Computer Science 1027a</TITLE> </HEAD> Stack Operations Dr. Gopika S, KJC, Bengaluru
  • 6. Uses of Stacks in Computing • Stack Calculators • To convert an infix expression to postfix, to make evaluation easier (more on this later) Infix expression: a * b + c Postfix expression: a b * c + • To evaluate postfix expressions (ditto) • Compilers • To convert infix expressions to postfix, to make translation of a high-level language such as Java or C to a lower level language easier Stack Operations Dr. Gopika S, KJC, Bengaluru
  • 7. Uses of Stacks in Computing • Call stack (Runtime stack) • Used by runtime system when methods are invoked, for method call / return processing (more on this later) • e.g. main calls method1 method1 calls method 2 method 2 returns … • Holds “call frame” containing local variables, parameters, etc. • Why is a stack structure used for this? Stack Operations Dr. Gopika S, KJC, Bengaluru
  • 8. Operations on a Collection • Every collection has a set of operations that define how we interact with it, for example: • Add elements • Remove elements • Determine if the collection is empty • Determine the collection's size Stack Operations Dr. Gopika S, KJC, Bengaluru
  • 9. Stack Operations • push: add an element at the top of the stack • pop: remove the element at the top of the stack • peek: examine the element at the top of the stack • It is not legal to access any element other than the one that is at the top of the stack! Stack Operations Dr. Gopika S, KJC, Bengaluru
  • 10. Operations on a Stack Operation Description push Adds an element to the top of the stack pop Removes an element from the top of the stack peek Examines the element at the top of the stack isEmpty Determines whether the stack is empty size Determines the number of elements in the stack toString Returns a string representation of the stack Stack Operations Dr. Gopika S, KJC, Bengaluru