SlideShare a Scribd company logo
1 of 18
Download to read offline
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

What's hot

Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structuresDeepa Rani
Β 
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES	UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES Kathirvel Ayyaswamy
Β 
Unit I-Data structures stack & Queue
Unit I-Data structures stack & QueueUnit I-Data structures stack & Queue
Unit I-Data structures stack & QueueDrkhanchanaR
Β 
basics of queues
basics of queuesbasics of queues
basics of queuessirmanohar
Β 
358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9sumitbardhan
Β 
Ml study notes id3
Ml study notes   id3Ml study notes   id3
Ml study notes id3Feri Handoyo
Β 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementationshaik faroq
Β 
Ds stack & queue
Ds   stack & queueDs   stack & queue
Ds stack & queueSunipa Bera
Β 
Applications of data structures
Applications of data structuresApplications of data structures
Applications of data structuresWipro
Β 
Data Structures 2
Data Structures 2Data Structures 2
Data Structures 2Dr.Umadevi V
Β 
9 big o-notation
9 big o-notation9 big o-notation
9 big o-notationirdginfo
Β 

What's hot (20)

Stack and queue
Stack and queueStack and queue
Stack and queue
Β 
Data Structures 01
Data Structures 01Data Structures 01
Data Structures 01
Β 
Link List
Link ListLink List
Link List
Β 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structures
Β 
Stack
StackStack
Stack
Β 
Queues
QueuesQueues
Queues
Β 
Stack
StackStack
Stack
Β 
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES	UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
Β 
Unit I-Data structures stack & Queue
Unit I-Data structures stack & QueueUnit I-Data structures stack & Queue
Unit I-Data structures stack & Queue
Β 
basics of queues
basics of queuesbasics of queues
basics of queues
Β 
358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9
Β 
Ml study notes id3
Ml study notes   id3Ml study notes   id3
Ml study notes id3
Β 
Essential NumPy
Essential NumPyEssential NumPy
Essential NumPy
Β 
Stack
StackStack
Stack
Β 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
Β 
Ds stack & queue
Ds   stack & queueDs   stack & queue
Ds stack & queue
Β 
Applications of data structures
Applications of data structuresApplications of data structures
Applications of data structures
Β 
Data Structures 2
Data Structures 2Data Structures 2
Data Structures 2
Β 
9 big o-notation
9 big o-notation9 big o-notation
9 big o-notation
Β 
Stack converted
Stack convertedStack converted
Stack converted
Β 

Similar to Algorithm and Data Structure - Stack

Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdfTobyWtf
Β 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueBalwant Gorad
Β 
Stack and queue
Stack and queueStack and queue
Stack and queueCHANDAN KUMAR
Β 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queuePulkitmodi1998
Β 
stack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptxstack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptxHusnainNaqvi2
Β 
Data structure week y 5
Data structure week y 5Data structure week y 5
Data structure week y 5karmuhtam
Β 
Chapter 5-stack.pptx
Chapter 5-stack.pptxChapter 5-stack.pptx
Chapter 5-stack.pptxHalid Assen
Β 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptxskilljiolms
Β 
Stack in Data Structure
Stack in Data StructureStack in Data Structure
Stack in Data StructureUshaP15
Β 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptxSonaPathak4
Β 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and ApplicationsSagacious IT Solution
Β 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.pptSeethaDinesh
Β 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queueRajkiran Nadar
Β 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdfSeethaDinesh
Β 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdfSeethaDinesh
Β 

Similar to Algorithm and Data Structure - Stack (20)

Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
Β 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
Β 
Stack and queue
Stack and queueStack and queue
Stack and queue
Β 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
Β 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Β 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
Β 
stack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptxstack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptx
Β 
Data structure week y 5
Data structure week y 5Data structure week y 5
Data structure week y 5
Β 
Chapter 5-stack.pptx
Chapter 5-stack.pptxChapter 5-stack.pptx
Chapter 5-stack.pptx
Β 
Team 3
Team 3Team 3
Team 3
Β 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
Β 
Stack in Data Structure
Stack in Data StructureStack in Data Structure
Stack in Data Structure
Β 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
Β 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
Β 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
Β 
Stack and Queue
Stack and QueueStack and Queue
Stack and Queue
Β 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
Β 
Stacks
StacksStacks
Stacks
Β 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
Β 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
Β 

More from AndiNurkholis1

Mobile Programming - 10 Firebase
Mobile Programming - 10 FirebaseMobile Programming - 10 Firebase
Mobile Programming - 10 FirebaseAndiNurkholis1
Β 
Mobile Programming - 9 Profile UI, Navigation Basic and Splash Screen
Mobile Programming - 9 Profile UI, Navigation Basic and Splash ScreenMobile Programming - 9 Profile UI, Navigation Basic and Splash Screen
Mobile Programming - 9 Profile UI, Navigation Basic and Splash ScreenAndiNurkholis1
Β 
Mobile Programming - 8 Progress Bar, Draggable Music Knob, Timer
Mobile Programming - 8 Progress Bar, Draggable Music Knob, TimerMobile Programming - 8 Progress Bar, Draggable Music Knob, Timer
Mobile Programming - 8 Progress Bar, Draggable Music Knob, TimerAndiNurkholis1
Β 
Mobile Programming - 7 Side Effects, Effect Handlers, and Simple Animations
Mobile Programming - 7 Side Effects, Effect Handlers, and Simple AnimationsMobile Programming - 7 Side Effects, Effect Handlers, and Simple Animations
Mobile Programming - 7 Side Effects, Effect Handlers, and Simple AnimationsAndiNurkholis1
Β 
Mobile Programming - 6 Textfields, Button, Showing Snackbars and Lists
Mobile Programming - 6 Textfields, Button, Showing Snackbars and ListsMobile Programming - 6 Textfields, Button, Showing Snackbars and Lists
Mobile Programming - 6 Textfields, Button, Showing Snackbars and ListsAndiNurkholis1
Β 
Mobile Programming - 5 Stylling Text and State
Mobile Programming - 5 Stylling Text and StateMobile Programming - 5 Stylling Text and State
Mobile Programming - 5 Stylling Text and StateAndiNurkholis1
Β 
Mobile Programming - 4 Modifiers and Image Card
Mobile Programming - 4 Modifiers and Image CardMobile Programming - 4 Modifiers and Image Card
Mobile Programming - 4 Modifiers and Image CardAndiNurkholis1
Β 
Mobile Programming - 3 Rows, Column and Basic Sizing
Mobile Programming - 3 Rows, Column and Basic SizingMobile Programming - 3 Rows, Column and Basic Sizing
Mobile Programming - 3 Rows, Column and Basic SizingAndiNurkholis1
Β 
Algoritma dan Struktur Data (Python) - Struktur Data
Algoritma dan Struktur Data (Python) - Struktur DataAlgoritma dan Struktur Data (Python) - Struktur Data
Algoritma dan Struktur Data (Python) - Struktur DataAndiNurkholis1
Β 
Mobile Programming - 2 Jetpack Compose
Mobile Programming - 2 Jetpack ComposeMobile Programming - 2 Jetpack Compose
Mobile Programming - 2 Jetpack ComposeAndiNurkholis1
Β 
Mobile Programming - 1 Introduction
Mobile Programming - 1 IntroductionMobile Programming - 1 Introduction
Mobile Programming - 1 IntroductionAndiNurkholis1
Β 
Algoritma dan Struktur Data (Python) - Perulangan
Algoritma dan Struktur Data (Python) - PerulanganAlgoritma dan Struktur Data (Python) - Perulangan
Algoritma dan Struktur Data (Python) - PerulanganAndiNurkholis1
Β 
Algoritma dan Struktur Data (Python) - Percabangan
Algoritma dan Struktur Data (Python) - PercabanganAlgoritma dan Struktur Data (Python) - Percabangan
Algoritma dan Struktur Data (Python) - PercabanganAndiNurkholis1
Β 
Algoritma dan Struktur Data (Python) - Struktur I/O
Algoritma dan Struktur Data (Python) - Struktur I/OAlgoritma dan Struktur Data (Python) - Struktur I/O
Algoritma dan Struktur Data (Python) - Struktur I/OAndiNurkholis1
Β 
Algoritma dan Struktur Data (Python) - Notasi Algoritmik
Algoritma dan Struktur Data (Python) - Notasi AlgoritmikAlgoritma dan Struktur Data (Python) - Notasi Algoritmik
Algoritma dan Struktur Data (Python) - Notasi AlgoritmikAndiNurkholis1
Β 
Algoritma dan Struktur Data (Python) - Pengantar Algoritma
Algoritma dan Struktur Data (Python) - Pengantar AlgoritmaAlgoritma dan Struktur Data (Python) - Pengantar Algoritma
Algoritma dan Struktur Data (Python) - Pengantar AlgoritmaAndiNurkholis1
Β 
Algorithm and Data Structure - Binary Search
Algorithm and Data Structure - Binary SearchAlgorithm and Data Structure - Binary Search
Algorithm and Data Structure - Binary SearchAndiNurkholis1
Β 
Algorithm and Data Structure - Linear Search
Algorithm and Data Structure - Linear SearchAlgorithm and Data Structure - Linear Search
Algorithm and Data Structure - Linear SearchAndiNurkholis1
Β 
Algorithm and Data Structure - Modular Programming
Algorithm and Data Structure - Modular ProgrammingAlgorithm and Data Structure - Modular Programming
Algorithm and Data Structure - Modular ProgrammingAndiNurkholis1
Β 
Algorithm and Data Structure - Array and Struct
Algorithm and Data Structure - Array and StructAlgorithm and Data Structure - Array and Struct
Algorithm and Data Structure - Array and StructAndiNurkholis1
Β 

More from AndiNurkholis1 (20)

Mobile Programming - 10 Firebase
Mobile Programming - 10 FirebaseMobile Programming - 10 Firebase
Mobile Programming - 10 Firebase
Β 
Mobile Programming - 9 Profile UI, Navigation Basic and Splash Screen
Mobile Programming - 9 Profile UI, Navigation Basic and Splash ScreenMobile Programming - 9 Profile UI, Navigation Basic and Splash Screen
Mobile Programming - 9 Profile UI, Navigation Basic and Splash Screen
Β 
Mobile Programming - 8 Progress Bar, Draggable Music Knob, Timer
Mobile Programming - 8 Progress Bar, Draggable Music Knob, TimerMobile Programming - 8 Progress Bar, Draggable Music Knob, Timer
Mobile Programming - 8 Progress Bar, Draggable Music Knob, Timer
Β 
Mobile Programming - 7 Side Effects, Effect Handlers, and Simple Animations
Mobile Programming - 7 Side Effects, Effect Handlers, and Simple AnimationsMobile Programming - 7 Side Effects, Effect Handlers, and Simple Animations
Mobile Programming - 7 Side Effects, Effect Handlers, and Simple Animations
Β 
Mobile Programming - 6 Textfields, Button, Showing Snackbars and Lists
Mobile Programming - 6 Textfields, Button, Showing Snackbars and ListsMobile Programming - 6 Textfields, Button, Showing Snackbars and Lists
Mobile Programming - 6 Textfields, Button, Showing Snackbars and Lists
Β 
Mobile Programming - 5 Stylling Text and State
Mobile Programming - 5 Stylling Text and StateMobile Programming - 5 Stylling Text and State
Mobile Programming - 5 Stylling Text and State
Β 
Mobile Programming - 4 Modifiers and Image Card
Mobile Programming - 4 Modifiers and Image CardMobile Programming - 4 Modifiers and Image Card
Mobile Programming - 4 Modifiers and Image Card
Β 
Mobile Programming - 3 Rows, Column and Basic Sizing
Mobile Programming - 3 Rows, Column and Basic SizingMobile Programming - 3 Rows, Column and Basic Sizing
Mobile Programming - 3 Rows, Column and Basic Sizing
Β 
Algoritma dan Struktur Data (Python) - Struktur Data
Algoritma dan Struktur Data (Python) - Struktur DataAlgoritma dan Struktur Data (Python) - Struktur Data
Algoritma dan Struktur Data (Python) - Struktur Data
Β 
Mobile Programming - 2 Jetpack Compose
Mobile Programming - 2 Jetpack ComposeMobile Programming - 2 Jetpack Compose
Mobile Programming - 2 Jetpack Compose
Β 
Mobile Programming - 1 Introduction
Mobile Programming - 1 IntroductionMobile Programming - 1 Introduction
Mobile Programming - 1 Introduction
Β 
Algoritma dan Struktur Data (Python) - Perulangan
Algoritma dan Struktur Data (Python) - PerulanganAlgoritma dan Struktur Data (Python) - Perulangan
Algoritma dan Struktur Data (Python) - Perulangan
Β 
Algoritma dan Struktur Data (Python) - Percabangan
Algoritma dan Struktur Data (Python) - PercabanganAlgoritma dan Struktur Data (Python) - Percabangan
Algoritma dan Struktur Data (Python) - Percabangan
Β 
Algoritma dan Struktur Data (Python) - Struktur I/O
Algoritma dan Struktur Data (Python) - Struktur I/OAlgoritma dan Struktur Data (Python) - Struktur I/O
Algoritma dan Struktur Data (Python) - Struktur I/O
Β 
Algoritma dan Struktur Data (Python) - Notasi Algoritmik
Algoritma dan Struktur Data (Python) - Notasi AlgoritmikAlgoritma dan Struktur Data (Python) - Notasi Algoritmik
Algoritma dan Struktur Data (Python) - Notasi Algoritmik
Β 
Algoritma dan Struktur Data (Python) - Pengantar Algoritma
Algoritma dan Struktur Data (Python) - Pengantar AlgoritmaAlgoritma dan Struktur Data (Python) - Pengantar Algoritma
Algoritma dan Struktur Data (Python) - Pengantar Algoritma
Β 
Algorithm and Data Structure - Binary Search
Algorithm and Data Structure - Binary SearchAlgorithm and Data Structure - Binary Search
Algorithm and Data Structure - Binary Search
Β 
Algorithm and Data Structure - Linear Search
Algorithm and Data Structure - Linear SearchAlgorithm and Data Structure - Linear Search
Algorithm and Data Structure - Linear Search
Β 
Algorithm and Data Structure - Modular Programming
Algorithm and Data Structure - Modular ProgrammingAlgorithm and Data Structure - Modular Programming
Algorithm and Data Structure - Modular Programming
Β 
Algorithm and Data Structure - Array and Struct
Algorithm and Data Structure - Array and StructAlgorithm and Data Structure - Array and Struct
Algorithm and Data Structure - Array and Struct
Β 

Recently uploaded

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
Β 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
Β 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
Β 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
Β 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
Β 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
Β 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
Β 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
Β 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
Β 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
Β 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
Β 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
Β 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
Β 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
Β 
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)Wonjun Hwang
Β 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
Β 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
Β 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
Β 

Recently uploaded (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
Β 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Β 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Β 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Β 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
Β 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Β 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
Β 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
Β 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Β 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Β 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Β 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
Β 
Hot Sexy call girls in Panjabi Bagh πŸ” 9953056974 πŸ” Delhi escort Service
Hot Sexy call girls in Panjabi Bagh πŸ” 9953056974 πŸ” Delhi escort ServiceHot Sexy call girls in Panjabi Bagh πŸ” 9953056974 πŸ” Delhi escort Service
Hot Sexy call girls in Panjabi Bagh πŸ” 9953056974 πŸ” Delhi escort Service
Β 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
Β 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
Β 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Β 
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)
Β 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
Β 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Β 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Β 

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