SlideShare uma empresa Scribd logo
1 de 10
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

Mais conteúdo relacionado

Mais procurados

Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
multimedia9
 
A software agent controlling 2 robot arms in co-operating concurrent tasks
A software agent controlling 2 robot arms in co-operating concurrent tasksA software agent controlling 2 robot arms in co-operating concurrent tasks
A software agent controlling 2 robot arms in co-operating concurrent tasks
RuleML
 

Mais procurados (20)

Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Document clustering for forensic analysis an approach for improving compute...
Document clustering for forensic   analysis an approach for improving compute...Document clustering for forensic   analysis an approach for improving compute...
Document clustering for forensic analysis an approach for improving compute...
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
An Introduction To Python - Lists, Part 1
An Introduction To Python - Lists, Part 1An Introduction To Python - Lists, Part 1
An Introduction To Python - Lists, Part 1
 
Stack Data structure
Stack Data structureStack Data structure
Stack Data structure
 
Algorithm and Data Structure - Queue
Algorithm and Data Structure - QueueAlgorithm and Data Structure - Queue
Algorithm and Data Structure - Queue
 
Week 2 - Data Structures and Algorithms
Week 2 - Data Structures and AlgorithmsWeek 2 - Data Structures and Algorithms
Week 2 - Data Structures and Algorithms
 
Big O Notation
Big O NotationBig O Notation
Big O Notation
 
Algorithm and Data Structure - Stack
Algorithm and Data Structure - StackAlgorithm and Data Structure - Stack
Algorithm and Data Structure - Stack
 
Data Structures and Algorithm - Week 9 - Search Algorithms
Data Structures and Algorithm - Week 9 - Search AlgorithmsData Structures and Algorithm - Week 9 - Search Algorithms
Data Structures and Algorithm - Week 9 - Search Algorithms
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
 
Week 1 - Data Structures and Algorithms
Week 1 - Data Structures and AlgorithmsWeek 1 - Data Structures and Algorithms
Week 1 - Data Structures and Algorithms
 
Basic of Data Structure - Data Structure - Notes
Basic of Data Structure - Data Structure - NotesBasic of Data Structure - Data Structure - Notes
Basic of Data Structure - Data Structure - Notes
 
A software agent controlling 2 robot arms in co-operating concurrent tasks
A software agent controlling 2 robot arms in co-operating concurrent tasksA software agent controlling 2 robot arms in co-operating concurrent tasks
A software agent controlling 2 robot arms in co-operating concurrent tasks
 
Slide 1.-datastructure
Slide 1.-datastructureSlide 1.-datastructure
Slide 1.-datastructure
 
Implementation of queue using singly and doubly linked list.
Implementation of queue using singly and doubly linked list.Implementation of queue using singly and doubly linked list.
Implementation of queue using singly and doubly linked list.
 
Stacks in algorithems & data structure
Stacks in algorithems & data structureStacks in algorithems & data structure
Stacks in algorithems & data structure
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 
Data Structures 01
Data Structures 01Data Structures 01
Data Structures 01
 
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
 

Semelhante a Data Structures: Stack Operations

stack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptxstack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptx
HusnainNaqvi2
 
The Art of Database Experiments – PostgresConf Silicon Valley 2018 / San Jose
The Art of Database Experiments – PostgresConf Silicon Valley 2018 / San JoseThe Art of Database Experiments – PostgresConf Silicon Valley 2018 / San Jose
The Art of Database Experiments – PostgresConf Silicon Valley 2018 / San Jose
Nikolay Samokhvalov
 

Semelhante a Data Structures: Stack Operations (20)

PostgreSQL 9.4, 9.5 and Beyond @ COSCUP 2015 Taipei
PostgreSQL 9.4, 9.5 and Beyond @ COSCUP 2015 TaipeiPostgreSQL 9.4, 9.5 and Beyond @ COSCUP 2015 Taipei
PostgreSQL 9.4, 9.5 and Beyond @ COSCUP 2015 Taipei
 
Data Structures and Algorithm - Week 3 - Stacks and Queues
Data Structures and Algorithm - Week 3 - Stacks and QueuesData Structures and Algorithm - Week 3 - Stacks and Queues
Data Structures and Algorithm - Week 3 - Stacks and Queues
 
Data Structures
Data StructuresData Structures
Data Structures
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
CD3291 2.5 stack.pptx
CD3291 2.5 stack.pptxCD3291 2.5 stack.pptx
CD3291 2.5 stack.pptx
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
 
sweetu stacks.pdf
sweetu stacks.pdfsweetu stacks.pdf
sweetu stacks.pdf
 
9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
 
Unit I-Data structures stack & Queue
Unit I-Data structures stack & QueueUnit I-Data structures stack & Queue
Unit I-Data structures stack & Queue
 
Data Structure - Stacks
Data Structure - StacksData Structure - Stacks
Data Structure - Stacks
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
 
Building a Complex, Real-Time Data Management Application
Building a Complex, Real-Time Data Management ApplicationBuilding a Complex, Real-Time Data Management Application
Building a Complex, Real-Time Data Management Application
 
Javascript stack
Javascript   stackJavascript   stack
Javascript stack
 
linked list in c++
linked list in c++linked list in c++
linked list in c++
 
stack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptxstack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptx
 
The Art of Database Experiments – PostgresConf Silicon Valley 2018 / San Jose
The Art of Database Experiments – PostgresConf Silicon Valley 2018 / San JoseThe Art of Database Experiments – PostgresConf Silicon Valley 2018 / San Jose
The Art of Database Experiments – PostgresConf Silicon Valley 2018 / San Jose
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
 
Stacks and Queue,Concept of Stack,LIFO,Fifo,
Stacks and Queue,Concept of Stack,LIFO,Fifo,Stacks and Queue,Concept of Stack,LIFO,Fifo,
Stacks and Queue,Concept of Stack,LIFO,Fifo,
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
 

Mais de GopikaS12 (7)

Deadlock _Classic problems.pptx
Deadlock _Classic problems.pptxDeadlock _Classic problems.pptx
Deadlock _Classic problems.pptx
 
Introduction to Tree .pptx
Introduction to Tree .pptxIntroduction to Tree .pptx
Introduction to Tree .pptx
 
C Programming language - introduction
C Programming  language - introduction  C Programming  language - introduction
C Programming language - introduction
 
C formatted and unformatted input and output constructs
C  formatted and unformatted input and output constructsC  formatted and unformatted input and output constructs
C formatted and unformatted input and output constructs
 
Heap creation from elements - Step by step Approach
Heap creation  from elements - Step by step Approach Heap creation  from elements - Step by step Approach
Heap creation from elements - Step by step Approach
 
Net content in computer architecture
Net content in computer  architectureNet content in computer  architecture
Net content in computer architecture
 
It unit 1
It   unit 1It   unit 1
It unit 1
 

Último

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
INTERRUPT CONTROLLER 8259 MICROPROCESSOR
INTERRUPT CONTROLLER 8259 MICROPROCESSORINTERRUPT CONTROLLER 8259 MICROPROCESSOR
INTERRUPT CONTROLLER 8259 MICROPROCESSOR
TanishkaHira1
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Introduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptxIntroduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptx
hublikarsn
 

Último (20)

Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Adsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) pptAdsorption (mass transfer operations 2) ppt
Adsorption (mass transfer operations 2) ppt
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 
Compressing and Sparsifying LLM in GenAI Applications
Compressing and Sparsifying LLM in GenAI ApplicationsCompressing and Sparsifying LLM in GenAI Applications
Compressing and Sparsifying LLM in GenAI Applications
 
Introduction to Geographic Information Systems
Introduction to Geographic Information SystemsIntroduction to Geographic Information Systems
Introduction to Geographic Information Systems
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .ppt
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Post office management system project ..pdf
Post office management system project ..pdfPost office management system project ..pdf
Post office management system project ..pdf
 
INTERRUPT CONTROLLER 8259 MICROPROCESSOR
INTERRUPT CONTROLLER 8259 MICROPROCESSORINTERRUPT CONTROLLER 8259 MICROPROCESSOR
INTERRUPT CONTROLLER 8259 MICROPROCESSOR
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Introduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptxIntroduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptx
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 
8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 

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