SlideShare a Scribd company logo
3
Most read
7
Most read
16
Most read
Algorithm and
Data Structure
Andi Nurkholis, S.Kom, M.Kom
Study Program of Informatics
Faculty of Engineering and Computer Science
SY. 2020-2021
April 12, 2021
2
4 Stack
3
What is Stack?
Stack is a linear data structure which follows a
particular order in which the operations are
performed. The order may be LIFO (Last In First Out)
or FILO (First In Last Out)
In stacks, the insertion and deletion of elements
happen only at one endpoint of it.
4
Illustration
5
Stack
Operations
1) Push
2) Pop
3) Peek or Top
4) IsEmpty
5) IsFull
6
Push
Push: Adds an item in the stack. If the stack is full, then it is said to
be an Overflow condition.
Steps of Push
Step 1 − Checks if the stack is full.
Step 2 − If the stack is full, produces an error and exit.
Step 3 − If the stack is not full, increments top to
point next empty space.
Step 4 − Adds data element to the stack location,
where top is pointing.
Step 5 − Returns success.
7
8
Push Algorithm
begin procedure push: stack, data
if stack is full
return null
endif
top ← top + 1
stack[top] ← data
end procedure
9
Pop
Pop: Removes an item from the stack. The items are popped in
the reversed order in which they are pushed. If the stack is
empty, then it is said to be an Underflow condition.
Steps of Pop
Step 1 − Checks if the stack is empty.
Step 2 − If the stack is empty, produces an error and
exit.
Step 3 − If the stack is not empty, accesses the data
element at which top is pointing.
Step 4 − Decreases the value of top by 1.
Step 5 − Returns success.
10
Pop Algorithm
begin procedure pop: stack
if stack is empty
return null
endif
data ← stack[top]
top ← top - 1
return data
end procedure
11
Peek or Top
Peek or Top: Returns the element on top of the stack.
It takes O(1)O(1) time as finding the value stored at a
particular index in an array is a constant time
operation. The operation is to get the top data
element of the stack, without removing it
12
Peek Algorithm:
begin procedure peek
return stack[top]
end procedure
IsEmpty
IsEmpty: Checks whether the
stack is empty. Returns true if
stack is empty, else false.
IsEmpty Algorithm:
begin procedure isempty
if top less than 1
return true
else
return false
endif
end procedure
13
IsFull
IsEmpty: Checks whether
the stack is full. Returns true
if stack is full, else false.
IsFull Algorithm:
begin procedure isfull
if top equals to MAXSIZE
return true
else
return false
endif
end procedure
14
Working of Stack
This abstract data type​ can be implemented in C in
multiple ways. One such way is by using an array.
Pro of using an array:
No extra memory required to store the pointers.
Con of using an array:
The size of the stack is pre-set so it cannot increase
or decrease.
15
Stack Application
1. Balancing of symbols
2. Infix to Postfix /Prefix conversion
3. Redo-undo features at many places like editors, photoshop.
4. Forward and backward feature in web browsers
5. Used in many algorithms like Tower of Hanoi, tree traversals,
stock span problem, histogram problem.
16
Stack Application (Cont.)
6. Backtracking is one of the algorithm designing technique.
7. In Graph Algorithms like Topological Sorting and Strongly
Connected Components
8. In Memory management any modern computer uses stack as
the primary-management for a running purpose.
9. String reversal is also a another application of stack.
17
Thank You, Next …
Queue
April 12, 2021
Andi Nurkholis, S.Kom, M.Kom
Study Program of Informatics
Faculty of Engineering and Computer Science
SY. 2020-2021

More Related Content

PPTX
Stack and its Applications : Data Structures ADT
PPTX
Introduction to stack
PPT
PPSX
PPT
IP Address in data communication and computer notework.ppt
PPTX
PPTX
Data structure by Digvijay
PDF
STACK ( LIFO STRUCTURE) - Data Structure
Stack and its Applications : Data Structures ADT
Introduction to stack
IP Address in data communication and computer notework.ppt
Data structure by Digvijay
STACK ( LIFO STRUCTURE) - Data Structure

What's hot (20)

PPTX
Stack and its applications
PDF
PPTX
Java presentation on insertion sort
PPT
Stack a Data Structure
PPTX
Infix to postfix conversion
PPTX
Queue Implementation Using Array & Linked List
PPTX
Dynamic Polymorphism in C++
PPT
PPTX
Stack Data Structure
PPTX
Stacks in c++
PPTX
DATA STRUCTURE - STACK
PPTX
Stack of Data structure
PPTX
stack
PPTX
Searching, Sorting and Hashing Techniques
PPT
PDF
Algorithm and Data Structure - Queue
PPTX
PPTX
stacks and queues
PPSX
Data structure stack&queue basics
PPT
Stacks
Stack and its applications
Java presentation on insertion sort
Stack a Data Structure
Infix to postfix conversion
Queue Implementation Using Array & Linked List
Dynamic Polymorphism in C++
Stack Data Structure
Stacks in c++
DATA STRUCTURE - STACK
Stack of Data structure
stack
Searching, Sorting and Hashing Techniques
Algorithm and Data Structure - Queue
stacks and queues
Data structure stack&queue basics
Stacks
Ad

Similar to Algorithm and Data Structure - Stack (20)

PDF
PDF
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
PPTX
stack_ppt_DSA(sudipta samanta).pptx push,pop,peek operation
PPTX
stack (1).pptx
PDF
4-Stack --------------------------------in C++.pdf
PDF
PPTX
stack.pptx
PDF
DS UNIT 1.pdf
PDF
DS UNIT 1.pdf
PPTX
Stack in C.pptx
PPTX
Lecture#5 - Stack ADT.pptx
PPTX
Data Structure.pptx
PDF
Chapter 5 Stack and Queue.pdf
PDF
PPTX
The presentation on stack data structure
PPTX
STACK AND QUEUE CIRCULAR QUEUE PPTS.pptx
DOCX
Stacks in data structure
PDF
Stacks-and-Queues.pdf
PPTX
5.-Stacks.pptx
PPTX
STACK_IN_DATA STRUCTURE AND ALGORITHMS.pptx
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
stack_ppt_DSA(sudipta samanta).pptx push,pop,peek operation
stack (1).pptx
4-Stack --------------------------------in C++.pdf
stack.pptx
DS UNIT 1.pdf
DS UNIT 1.pdf
Stack in C.pptx
Lecture#5 - Stack ADT.pptx
Data Structure.pptx
Chapter 5 Stack and Queue.pdf
The presentation on stack data structure
STACK AND QUEUE CIRCULAR QUEUE PPTS.pptx
Stacks in data structure
Stacks-and-Queues.pdf
5.-Stacks.pptx
STACK_IN_DATA STRUCTURE AND ALGORITHMS.pptx
Ad

More from AndiNurkholis1 (20)

PDF
Data Structure - 4 Pointer & Linked List
PDF
Data Structure - 3 Array: Concept & Implementation
PDF
Data Structure - 1 Learning Contract
PDF
Data Structure - 2 Introduction of Data Structure
PDF
Struktur Data - 4 Pointer & Linked List
PDF
Struktur Data - 3 Array: Konsep & Implementasi
PDF
Struktur Data - 2 Pengantar Struktur Data
PDF
Struktur Data - 1 Kontrak Perkuliahan
PDF
Technopreneurship - 9 Analisis Biaya dan Keuangan
PDF
Pengantar Bisnis - 14 Manajemen Keuangan
PDF
Pengantar Bisnis - 13 Manajemen Operasi
PDF
Pengantar Bisnis - 12 Kebijakan Harga
PDF
Pengantar Bisnis - 11 Kebijakan Distribusi
PDF
Technopreneurship - 8 Manajemen Sumber Daya Manusia
PDF
Pengantar Bisnis - 10 Kebijakan Produk
PDF
Technopreneurship - 7 Manajemen Pemasaran dan Operasional Bisnis
PDF
Pengantar Bisnis - 9 Manajemen Pemasaran
PDF
Technopreneurship - 6 Business Plan
PDF
Pengantar Bisnis - 8 Kepemimpinan
PDF
Technopreneurship - 5 Model Bisnis
Data Structure - 4 Pointer & Linked List
Data Structure - 3 Array: Concept & Implementation
Data Structure - 1 Learning Contract
Data Structure - 2 Introduction of Data Structure
Struktur Data - 4 Pointer & Linked List
Struktur Data - 3 Array: Konsep & Implementasi
Struktur Data - 2 Pengantar Struktur Data
Struktur Data - 1 Kontrak Perkuliahan
Technopreneurship - 9 Analisis Biaya dan Keuangan
Pengantar Bisnis - 14 Manajemen Keuangan
Pengantar Bisnis - 13 Manajemen Operasi
Pengantar Bisnis - 12 Kebijakan Harga
Pengantar Bisnis - 11 Kebijakan Distribusi
Technopreneurship - 8 Manajemen Sumber Daya Manusia
Pengantar Bisnis - 10 Kebijakan Produk
Technopreneurship - 7 Manajemen Pemasaran dan Operasional Bisnis
Pengantar Bisnis - 9 Manajemen Pemasaran
Technopreneurship - 6 Business Plan
Pengantar Bisnis - 8 Kepemimpinan
Technopreneurship - 5 Model Bisnis

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
sap open course for s4hana steps from ECC to s4
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Encapsulation theory and applications.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
KodekX | Application Modernization Development
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
Machine learning based COVID-19 study performance prediction
Understanding_Digital_Forensics_Presentation.pptx
Programs and apps: productivity, graphics, security and other tools
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
sap open course for s4hana steps from ECC to s4
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Unlocking AI with Model Context Protocol (MCP)
Network Security Unit 5.pdf for BCA BBA.
Mobile App Security Testing_ A Comprehensive Guide.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Encapsulation theory and applications.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
KodekX | Application Modernization Development
“AI and Expert System Decision Support & Business Intelligence Systems”

Algorithm and Data Structure - Stack

  • 1. Algorithm and Data Structure Andi Nurkholis, S.Kom, M.Kom Study Program of Informatics Faculty of Engineering and Computer Science SY. 2020-2021 April 12, 2021
  • 3. 3 What is Stack? Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO (Last In First Out) or FILO (First In Last Out) In stacks, the insertion and deletion of elements happen only at one endpoint of it.
  • 5. 5 Stack Operations 1) Push 2) Pop 3) Peek or Top 4) IsEmpty 5) IsFull
  • 6. 6 Push Push: Adds an item in the stack. If the stack is full, then it is said to be an Overflow condition.
  • 7. Steps of Push Step 1 − Checks if the stack is full. Step 2 − If the stack is full, produces an error and exit. Step 3 − If the stack is not full, increments top to point next empty space. Step 4 − Adds data element to the stack location, where top is pointing. Step 5 − Returns success. 7
  • 8. 8 Push Algorithm begin procedure push: stack, data if stack is full return null endif top ← top + 1 stack[top] ← data end procedure
  • 9. 9 Pop Pop: Removes an item from the stack. The items are popped in the reversed order in which they are pushed. If the stack is empty, then it is said to be an Underflow condition.
  • 10. Steps of Pop Step 1 − Checks if the stack is empty. Step 2 − If the stack is empty, produces an error and exit. Step 3 − If the stack is not empty, accesses the data element at which top is pointing. Step 4 − Decreases the value of top by 1. Step 5 − Returns success. 10
  • 11. Pop Algorithm begin procedure pop: stack if stack is empty return null endif data ← stack[top] top ← top - 1 return data end procedure 11
  • 12. Peek or Top Peek or Top: Returns the element on top of the stack. It takes O(1)O(1) time as finding the value stored at a particular index in an array is a constant time operation. The operation is to get the top data element of the stack, without removing it 12 Peek Algorithm: begin procedure peek return stack[top] end procedure
  • 13. IsEmpty IsEmpty: Checks whether the stack is empty. Returns true if stack is empty, else false. IsEmpty Algorithm: begin procedure isempty if top less than 1 return true else return false endif end procedure 13
  • 14. IsFull IsEmpty: Checks whether the stack is full. Returns true if stack is full, else false. IsFull Algorithm: begin procedure isfull if top equals to MAXSIZE return true else return false endif end procedure 14
  • 15. Working of Stack This abstract data type​ can be implemented in C in multiple ways. One such way is by using an array. Pro of using an array: No extra memory required to store the pointers. Con of using an array: The size of the stack is pre-set so it cannot increase or decrease. 15
  • 16. Stack Application 1. Balancing of symbols 2. Infix to Postfix /Prefix conversion 3. Redo-undo features at many places like editors, photoshop. 4. Forward and backward feature in web browsers 5. Used in many algorithms like Tower of Hanoi, tree traversals, stock span problem, histogram problem. 16
  • 17. Stack Application (Cont.) 6. Backtracking is one of the algorithm designing technique. 7. In Graph Algorithms like Topological Sorting and Strongly Connected Components 8. In Memory management any modern computer uses stack as the primary-management for a running purpose. 9. String reversal is also a another application of stack. 17
  • 18. Thank You, Next … Queue April 12, 2021 Andi Nurkholis, S.Kom, M.Kom Study Program of Informatics Faculty of Engineering and Computer Science SY. 2020-2021