SlideShare a Scribd company logo
1 of 23
Download to read offline
www.ieee.org
www.ieee.org
Hash Maps, Stacks and Queues
Chidera Anichebe
dera@ieee.org
www.ieee.org
What is a Hashmap?
▸ A Hashmap is a data structure which stores data in an associative manner. In
a hashmap, data is stored in an array format, where each data value has its
own unique index value. Access of data becomes very fast if we know the
index of the desired data.
▸ Thus, it becomes a data structure in which insertion and search operations
are very fast irrespective of the size of the data. A hashmap uses an array as
a storage medium and uses hash technique to generate an index where an
element is to be inserted or is to be located from.
2
www.ieee.org
What is hashing?
▸ Hashing is a technique to convert a range of key values into a range of
indexes of an array.
▸ Hashing is an example of a space-time tradeoff. If memory is infinite, the
entire key can be used directly as an index to locate its value with a single
memory access. On the other hand, if infinite time is available, values can be
stored without regard for their keys, and a binary search or linear search can
be used to retrieve the element
3
www.ieee.org
Basic operations of a hashmap
▸ The following are the basic primary operations of a hashmap:
▸ Search – Searches an element in a hashmap
▸ Insert – Inserts an element in a hashmap
▸ Delete – Deletes an element from a hashmap
4
www.ieee.org
Collision resolution
▸ A search algorithm that uses hashing consists of two parts. The first part is
computing a hash function which transforms the search key into an array
index. The ideal case is such that no two search keys hashes to the same
array index. However, this is not always the case and is impossible to
guarantee for unseen given data. Hence the second part of the algorithm is
collision resolution. The two common methods for collision resolution are
separate chaining and open addressing:
5
- Separate chaining: this process involves building
a linked list with key–value pair for each search array
index.
- Open addressing: this is another collision resolution
technique in which every entry records are stored in the
bucket array itself, and the hash resolution is performed
through probing
www.ieee.org
What is a Stack?
▸ A stack is an Abstract Data Type (ADT), commonly used in most
programming languages. It is named stack as it behaves like a real-world
stack, for example – a deck of cards or a pile of plates, etc.
▸ This features makes it a LIFO data structure. LIFO stands for Last-In-First-
Out. Here, the element which is placed (inserted or added) last, is accessed
first. In stack terminology, insertion operation is called PUSH operation and
removal operation is called POP operation
6
www.ieee.org
The representation of a Stack
▸ A stack can be implemented by means of an array, struct, pointer or linked
list. Stack can either be a fixed size one or it may have a sense of dynamic
resizing
7
www.ieee.org
Basic operations of a Stack
▸ Stack operations may involve initializing the stack, using it and then de-
initializing it. Apart from these basic stuffs, a stack is used for the following
two primary operations:
▸ - push() – pushing (storing) an element on the stack
▸ - pop() – removing (accessing) an element from the stack
▸ To use a stack efficiently, we need to check the status of the stack as well
using these additional functionality:
▸ - peek() – get the top data element of the stack, without removing it
▸ - isFull() – check if the stack is full
▸ - isEmpty() – check if the stack is empty
8
www.ieee.org
Stack operations
▸ The process of putting a new data element onto stack is known as a Push
operation. Push operation involves a series of steps:
▸ Step 1 – Checks if the stack is full
▸ Step 2 – If the stack is full, produces an error and exits
▸ Step 3 – If the stack is not full, increments top to point to next empty space
▸ Step 4 – Adds data element to the stack location, where top is pointing
▸ Step 5 – Returns with success
The push operation
9
www.ieee.org
Stack operations
▸ Accessing the content while removing it from the stack, is known as a POP
operation. In an array implementation of pop() operation, the data element is
not actually removed, instead top is decremented to a lower position in the
stack to point to the next value. But in linked-list implementation, pop()
actually removes data element and frees memory space.
▸ A pop operation may involve the following steps –
▸ Step 1 – Checks if the stack is empty
▸ Step 2 – If the stack is empty, produces an error and exits
▸ Step 3 – If the stack is not empty, accessed the data element at which top is
pointing
▸ Step 4 – Decreases the value of top by 1
▸ Step 5 - Returns gracefully with success
The pop operation
10
www.ieee.org
Stack pop() operation pictorially
11
www.ieee.org
Applications of the Stack ADT
▸ The stack is a last-in, first-out data structure. The developer can use the stack
in the following use cases:
▸ Expression evaluation and syntax parsing
▸ Finding the correct path in a maze using backtracking
▸ Runtime memory management
▸ Recursion function
Why should we care?
12
www.ieee.org
What is a Queue?
▸ A queue is an abstract data structure, somewhat similar to stacks. One end is
always used to insert data (enqueue) and the other is used to remove data
(dequeue). Queue follows First-In-First-Out methodology i.e., the data item
stored first will be accessed first.
13
www.ieee.org
The representation of a Queue
▸ As we now understand that in queue, we access both ends for different
reasons. The diagram below tries to explain queue representation as a data
structure. Queues can also be implemented using Arrays, Linked Lists,
Pointers and Structs
14
www.ieee.org
Basic operations of a Queue
▸ Queue operations may involve initializing or defining the queue, utilizing it,
and then completely erasing it from the memory. Here we shall try to
understand the basic operations associated with queues:
▸ enqueue() – add (store) an item to the queue
▸ dequeue() – remove (access) an item from the queue
▸ Few more functions are required to make the above-mentioned queue
operation efficient. These are:
▸ peek() – gets the element at the front of the queue without removing it
▸ isfull() – checks if the queue is full
▸ isempty() – checks if the queue is empty
▸ In queue, we always dequeue (or access) data, pointed by front pointer and
while enqueuing (or storing) data in the queue we take help of rear pointer
15
www.ieee.org
Queue operations
▸ Queues maintain two data pointers, front and rear. Therefore, its operations
are comparatively difficult to implement than that of stacks.
▸ The following steps should be taken to enqueue (insert) data into a queue:
▸ Step 1 – Check if the queue is full
▸ Step 2 – If the queue is full, produce overflow error and exit
▸ Step 3 – If the queue is not full, increment rear pointer to point to the next
empty space
▸ Step 4 – Add data element to the queue location, where the rear is pointing
▸ Step 5 – Return success
The enqueue operation
16
www.ieee.org
Queue enqueue() operation pictorially
17
www.ieee.org
Queue operations
▸ Accessing data from the queue is a process of two tasks – access the data
where front is pointing and remove the data after access. The following steps
are taken to perform dequeue operation:
▸ Step 1 – Check if the queue is empty
▸ Step 2 – If the queue is empty, produce underflow error and exit
▸ Step 3 – If the queue is not empty, access the data where front is pointing
▸ Step 4 – Increment front pointer to point to the next available data element
▸ Step 5 – Return gracefully with success
The dequeue operation
18
www.ieee.org
Queue dequeue() operation pictorially
19
www.ieee.org
Applications of the Queue ADT
▸ The queue is a first in, first out (FIFO) data structure. The developer can use
Queue in the following use cases:
▸ When you need an order
▸ When you want data processed in First In First Out order
▸ If the developer wants to add or remove both ends, they can use the queue or
a double-ended queue
Why should we care?
20
www.ieee.org
PRACTICAL SESSION…
21
www.ieee.org
22
Questions?
www.ieee.org
www.ieee.org
Thank you!
Let’s connect
23
https://twitter.com/starlingvibe
https://linkedin.com/in/chideraanichebe
https://github.com/starlingvibes

More Related Content

Similar to Hashmaps, Stacks and Queues by Chidera Anichebe.pdf

Similar to Hashmaps, Stacks and Queues by Chidera Anichebe.pdf (20)

Stack
StackStack
Stack
 
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
 
Queue and its operations
Queue and its operationsQueue and its operations
Queue and its operations
 
Basic Queue Operation in DataStructure.pptx
Basic Queue Operation in DataStructure.pptxBasic Queue Operation in DataStructure.pptx
Basic Queue Operation in DataStructure.pptx
 
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
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
 
Algorithm and Data Structure - Queue
Algorithm and Data Structure - QueueAlgorithm and Data Structure - Queue
Algorithm and Data Structure - Queue
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue
QueueQueue
Queue
 
chapter three ppt.pptx
chapter three ppt.pptxchapter three ppt.pptx
chapter three ppt.pptx
 
Data Structure Using C
Data Structure Using CData Structure Using C
Data Structure Using C
 
Stack organization
Stack organizationStack organization
Stack organization
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
 
Stack
StackStack
Stack
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
Data structures
Data structuresData structures
Data structures
 
Intro ds
Intro dsIntro ds
Intro ds
 
Data structure
Data structureData structure
Data structure
 

Recently uploaded

Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...soginsider
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stageAbc194748
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
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 ptxJIT KUMAR GUPTA
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Call Girls Mumbai
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksMagic Marks
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxnuruddin69
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 

Recently uploaded (20)

Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 
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
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
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
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 

Hashmaps, Stacks and Queues by Chidera Anichebe.pdf

  • 1. www.ieee.org www.ieee.org Hash Maps, Stacks and Queues Chidera Anichebe dera@ieee.org
  • 2. www.ieee.org What is a Hashmap? ▸ A Hashmap is a data structure which stores data in an associative manner. In a hashmap, data is stored in an array format, where each data value has its own unique index value. Access of data becomes very fast if we know the index of the desired data. ▸ Thus, it becomes a data structure in which insertion and search operations are very fast irrespective of the size of the data. A hashmap uses an array as a storage medium and uses hash technique to generate an index where an element is to be inserted or is to be located from. 2
  • 3. www.ieee.org What is hashing? ▸ Hashing is a technique to convert a range of key values into a range of indexes of an array. ▸ Hashing is an example of a space-time tradeoff. If memory is infinite, the entire key can be used directly as an index to locate its value with a single memory access. On the other hand, if infinite time is available, values can be stored without regard for their keys, and a binary search or linear search can be used to retrieve the element 3
  • 4. www.ieee.org Basic operations of a hashmap ▸ The following are the basic primary operations of a hashmap: ▸ Search – Searches an element in a hashmap ▸ Insert – Inserts an element in a hashmap ▸ Delete – Deletes an element from a hashmap 4
  • 5. www.ieee.org Collision resolution ▸ A search algorithm that uses hashing consists of two parts. The first part is computing a hash function which transforms the search key into an array index. The ideal case is such that no two search keys hashes to the same array index. However, this is not always the case and is impossible to guarantee for unseen given data. Hence the second part of the algorithm is collision resolution. The two common methods for collision resolution are separate chaining and open addressing: 5 - Separate chaining: this process involves building a linked list with key–value pair for each search array index. - Open addressing: this is another collision resolution technique in which every entry records are stored in the bucket array itself, and the hash resolution is performed through probing
  • 6. www.ieee.org What is a Stack? ▸ A stack is an Abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example – a deck of cards or a pile of plates, etc. ▸ This features makes it a LIFO data structure. LIFO stands for Last-In-First- Out. Here, the element which is placed (inserted or added) last, is accessed first. In stack terminology, insertion operation is called PUSH operation and removal operation is called POP operation 6
  • 7. www.ieee.org The representation of a Stack ▸ A stack can be implemented by means of an array, struct, pointer or linked list. Stack can either be a fixed size one or it may have a sense of dynamic resizing 7
  • 8. www.ieee.org Basic operations of a Stack ▸ Stack operations may involve initializing the stack, using it and then de- initializing it. Apart from these basic stuffs, a stack is used for the following two primary operations: ▸ - push() – pushing (storing) an element on the stack ▸ - pop() – removing (accessing) an element from the stack ▸ To use a stack efficiently, we need to check the status of the stack as well using these additional functionality: ▸ - peek() – get the top data element of the stack, without removing it ▸ - isFull() – check if the stack is full ▸ - isEmpty() – check if the stack is empty 8
  • 9. www.ieee.org Stack operations ▸ The process of putting a new data element onto stack is known as a Push operation. Push operation involves a series of steps: ▸ Step 1 – Checks if the stack is full ▸ Step 2 – If the stack is full, produces an error and exits ▸ Step 3 – If the stack is not full, increments top to point to next empty space ▸ Step 4 – Adds data element to the stack location, where top is pointing ▸ Step 5 – Returns with success The push operation 9
  • 10. www.ieee.org Stack operations ▸ Accessing the content while removing it from the stack, is known as a POP operation. In an array implementation of pop() operation, the data element is not actually removed, instead top is decremented to a lower position in the stack to point to the next value. But in linked-list implementation, pop() actually removes data element and frees memory space. ▸ A pop operation may involve the following steps – ▸ Step 1 – Checks if the stack is empty ▸ Step 2 – If the stack is empty, produces an error and exits ▸ Step 3 – If the stack is not empty, accessed the data element at which top is pointing ▸ Step 4 – Decreases the value of top by 1 ▸ Step 5 - Returns gracefully with success The pop operation 10
  • 12. www.ieee.org Applications of the Stack ADT ▸ The stack is a last-in, first-out data structure. The developer can use the stack in the following use cases: ▸ Expression evaluation and syntax parsing ▸ Finding the correct path in a maze using backtracking ▸ Runtime memory management ▸ Recursion function Why should we care? 12
  • 13. www.ieee.org What is a Queue? ▸ A queue is an abstract data structure, somewhat similar to stacks. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue). Queue follows First-In-First-Out methodology i.e., the data item stored first will be accessed first. 13
  • 14. www.ieee.org The representation of a Queue ▸ As we now understand that in queue, we access both ends for different reasons. The diagram below tries to explain queue representation as a data structure. Queues can also be implemented using Arrays, Linked Lists, Pointers and Structs 14
  • 15. www.ieee.org Basic operations of a Queue ▸ Queue operations may involve initializing or defining the queue, utilizing it, and then completely erasing it from the memory. Here we shall try to understand the basic operations associated with queues: ▸ enqueue() – add (store) an item to the queue ▸ dequeue() – remove (access) an item from the queue ▸ Few more functions are required to make the above-mentioned queue operation efficient. These are: ▸ peek() – gets the element at the front of the queue without removing it ▸ isfull() – checks if the queue is full ▸ isempty() – checks if the queue is empty ▸ In queue, we always dequeue (or access) data, pointed by front pointer and while enqueuing (or storing) data in the queue we take help of rear pointer 15
  • 16. www.ieee.org Queue operations ▸ Queues maintain two data pointers, front and rear. Therefore, its operations are comparatively difficult to implement than that of stacks. ▸ The following steps should be taken to enqueue (insert) data into a queue: ▸ Step 1 – Check if the queue is full ▸ Step 2 – If the queue is full, produce overflow error and exit ▸ Step 3 – If the queue is not full, increment rear pointer to point to the next empty space ▸ Step 4 – Add data element to the queue location, where the rear is pointing ▸ Step 5 – Return success The enqueue operation 16
  • 18. www.ieee.org Queue operations ▸ Accessing data from the queue is a process of two tasks – access the data where front is pointing and remove the data after access. The following steps are taken to perform dequeue operation: ▸ Step 1 – Check if the queue is empty ▸ Step 2 – If the queue is empty, produce underflow error and exit ▸ Step 3 – If the queue is not empty, access the data where front is pointing ▸ Step 4 – Increment front pointer to point to the next available data element ▸ Step 5 – Return gracefully with success The dequeue operation 18
  • 20. www.ieee.org Applications of the Queue ADT ▸ The queue is a first in, first out (FIFO) data structure. The developer can use Queue in the following use cases: ▸ When you need an order ▸ When you want data processed in First In First Out order ▸ If the developer wants to add or remove both ends, they can use the queue or a double-ended queue Why should we care? 20