SlideShare a Scribd company logo
7
Most read
14
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
PDF
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
PPT
Abstract data types (adt) intro to data structure part 2
PPTX
Introduction to stack
PPT
Stacks & Queues By Ms. Niti Arora
PPTX
Presentation on queue
PPTX
Data structure Stack
PPTX
Queue - Data Structure - Notes
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
Abstract data types (adt) intro to data structure part 2
Introduction to stack
Stacks & Queues By Ms. Niti Arora
Presentation on queue
Data structure Stack
Queue - Data Structure - Notes

What's hot (20)

PPT
Queue data structure
PPTX
stacks and queues
PPTX
Queue ppt
PPT
PPT
Searching in c language
PPTX
Stack data structure in Data Structure using C
PPSX
PPTX
Project on stack Data structure
PPTX
STACKS IN DATASTRUCTURE
PPT
Abstract data types
PPTX
What is sparse matrix
PPT
Sorting Techniques
PPT
Data structure
PPTX
Stack - Data Structure
PPT
Data structure lecture7
PPTX
Hashing Technique In Data Structures
PPTX
queue & its applications
PPT
linked list
PPTX
Datastructures in python
Queue data structure
stacks and queues
Queue ppt
Searching in c language
Stack data structure in Data Structure using C
Project on stack Data structure
STACKS IN DATASTRUCTURE
Abstract data types
What is sparse matrix
Sorting Techniques
Data structure
Stack - Data Structure
Data structure lecture7
Hashing Technique In Data Structures
queue & its applications
linked list
Datastructures in python
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
PDF
STACK ( LIFO STRUCTURE) - Data Structure
PPTX
Lecture#5 - Stack ADT.pptx
PPTX
Data Structure.pptx
PDF
Chapter 5 Stack and Queue.pdf
PDF
PPT
Stacks
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
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
STACK ( LIFO STRUCTURE) - Data Structure
Lecture#5 - Stack ADT.pptx
Data Structure.pptx
Chapter 5 Stack and Queue.pdf
Stacks
The presentation on stack data structure
STACK AND QUEUE CIRCULAR QUEUE PPTS.pptx
Stacks in data structure
Stacks-and-Queues.pdf
Ad

More from AndiNurkholis1 (20)

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
PDF
Technopreneurship - 4 Studi Kelayakan Usaha
PDF
Pengantar Bisnis - 7 Motivasi Kerja
PDF
Pengantar Bisnis - 6 Manajemen Sumber Daya Manusia
PDF
Pengantar Bisnis - 5 Pengelolaan & Pengorganisasian Bisnis
PDF
Technopreneurship - 3 Ide dan Prinsip Bisnis
PDF
Pengantar Bisnis - 4 Bentuk Organisasi Bisnis
PDF
Technopreneurship - 2 Pengantar Technopreneurship
PDF
Pengantar Bisnis - 3 Globalisasi Ekonomi & Bisnis Internasional
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
Technopreneurship - 4 Studi Kelayakan Usaha
Pengantar Bisnis - 7 Motivasi Kerja
Pengantar Bisnis - 6 Manajemen Sumber Daya Manusia
Pengantar Bisnis - 5 Pengelolaan & Pengorganisasian Bisnis
Technopreneurship - 3 Ide dan Prinsip Bisnis
Pengantar Bisnis - 4 Bentuk Organisasi Bisnis
Technopreneurship - 2 Pengantar Technopreneurship
Pengantar Bisnis - 3 Globalisasi Ekonomi & Bisnis Internasional

Recently uploaded (20)

PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Omni-Path Integration Expertise Offered by Nor-Tech
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Event Presentation Google Cloud Next Extended 2025
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
Smarter Business Operations Powered by IoT Remote Monitoring
PPTX
CroxyProxy Instagram Access id login.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Reimagining Insurance: Connected Data for Confident Decisions.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PDF
DevOps & Developer Experience Summer BBQ
GamePlan Trading System Review: Professional Trader's Honest Take
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Omni-Path Integration Expertise Offered by Nor-Tech
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Event Presentation Google Cloud Next Extended 2025
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Advanced Soft Computing BINUS July 2025.pdf
Smarter Business Operations Powered by IoT Remote Monitoring
CroxyProxy Instagram Access id login.pptx
MYSQL Presentation for SQL database connectivity
Reimagining Insurance: Connected Data for Confident Decisions.pdf
NewMind AI Weekly Chronicles - August'25 Week I
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
Understanding_Digital_Forensics_Presentation.pptx
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
madgavkar20181017ppt McKinsey Presentation.pdf
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
DevOps & Developer Experience Summer BBQ

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