SlideShare a Scribd company logo
1 of 19
Download to read offline
QUEUE ADT
Jun Y. Ercia
The Queue ADT
Objectives
• examine queue processing
• define a queue abstract data type
• demonstrate how a queue can be used to solve problems
• examine various queue implementations
• compare queue implementations
The Queue ADT
Data
 a collection whose elements are added at one end (the rear or
tail of the queue) and removed from the other end (the front or
head of the queue)
 a queue is a FIFO (first in, first out) data structure
Example
• Line of people waiting at a bank machine
• Collection of documents sent to a shared printer
Note • Items are removed from a queue in the
same order as they were inserted
• it is not legal to access the elements in
the middle of the queue!
Operations on a Queue
Queue Errors
1. Underflow – occurs when trying to Dequeue (or Front at) an empty queue
2. Overflow – occurs when trying to Enqueue onto an already full queue.
Uses of Queues in Computing
Queue is useful for any for any kind of problem involving FIFO data
1. printer queue
2. keyboard input buffer
3. GUI event queue
4. in simulation studies, where the goal is to reduce waiting times:
− optimize the flow of traffic at a traffic light
− determine number of cashiers to have on duty at a grocery store at different times of day.
Implementation of Queue ADT
1. Array implementation of Queue
• The entire queue is represented by an array together with two external “pointers” to keep track of the
front and rear.
• Suitable for applications in which the maximum queue size is known ahead of
time.
front Index prior the front element
rear Index of the rear (last) element
Both pointers are initially set to -1 (i.e. point before the
first cell of the array.
Code for adding an element to the rear [tail] of
the queue
Code for removing an element from the front
of the queue.
Code for determining whether the queue is
empty
Code for determining whether the queue is full
Code for retrieving the element at the
front[head] of the queue
Code for making the queue empty
Implementation of Queue ADT
1. Linked List implementation of Queue
• The entire queue is represented by a linked list of nodes
together with a pointer to the first node of the linked list
(front) and a pointer to the end of the linked list (rear).
• Suitable for applications in which the maximum queue
size is not known beforehand.
Note ▪ With a linked-list representation, overflow
will not happen (unless you exhaust
memory, which is another kind of problem)
▪ Underflow can happen, and should be
handled.
Code for adding an element to the rear [tail] of
the queue
Code for removing an element from the front
of the queue.
Code for determining whether the queue is
empty
Code for retrieving the element at the
front[head] of the queue
Code for making the queue empty

More Related Content

Similar to Lesson 4 - Queue ADT.pdf

Data structure and algorithm using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using javaNarayan Sau
 
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4sumitbardhan
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Self-Employed
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in CJabs6
 
DSJ_Unit I & II.pdf
DSJ_Unit I & II.pdfDSJ_Unit I & II.pdf
DSJ_Unit I & II.pdfArumugam90
 
ds 1 Introduction to Data Structures.ppt
ds 1 Introduction to Data Structures.pptds 1 Introduction to Data Structures.ppt
ds 1 Introduction to Data Structures.pptAlliVinay1
 
Lesson 3 - Stack ADT.pdf
Lesson 3 - Stack ADT.pdfLesson 3 - Stack ADT.pdf
Lesson 3 - Stack ADT.pdfLeandroJrErcia
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsJulie Iskander
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddumaneesh boddu
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1blessyboban92
 
Introduction data structure
Introduction data structureIntroduction data structure
Introduction data structureMuhammad Ismail
 
Basic Queue Operation in DataStructure.pptx
Basic Queue Operation in DataStructure.pptxBasic Queue Operation in DataStructure.pptx
Basic Queue Operation in DataStructure.pptxLakshmiSamivel
 
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 QueuesFerdin Joe John Joseph PhD
 

Similar to Lesson 4 - Queue ADT.pdf (20)

Data structure and algorithm using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using java
 
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in C
 
DSJ_Unit I & II.pdf
DSJ_Unit I & II.pdfDSJ_Unit I & II.pdf
DSJ_Unit I & II.pdf
 
ds 1 Introduction to Data Structures.ppt
ds 1 Introduction to Data Structures.pptds 1 Introduction to Data Structures.ppt
ds 1 Introduction to Data Structures.ppt
 
Data structures
Data structuresData structures
Data structures
 
Lesson 3 - Stack ADT.pdf
Lesson 3 - Stack ADT.pdfLesson 3 - Stack ADT.pdf
Lesson 3 - Stack ADT.pdf
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
UNIT-2.pptx
UNIT-2.pptxUNIT-2.pptx
UNIT-2.pptx
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Data Structures
Data StructuresData Structures
Data Structures
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
 
Introduction data structure
Introduction data structureIntroduction data structure
Introduction data structure
 
Basic Queue Operation in DataStructure.pptx
Basic Queue Operation in DataStructure.pptxBasic Queue Operation in DataStructure.pptx
Basic Queue Operation in DataStructure.pptx
 
Queue
QueueQueue
Queue
 
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 - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]
 

Recently uploaded

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 

Recently uploaded (20)

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 

Lesson 4 - Queue ADT.pdf

  • 2. The Queue ADT Objectives • examine queue processing • define a queue abstract data type • demonstrate how a queue can be used to solve problems • examine various queue implementations • compare queue implementations
  • 3. The Queue ADT Data  a collection whose elements are added at one end (the rear or tail of the queue) and removed from the other end (the front or head of the queue)  a queue is a FIFO (first in, first out) data structure Example • Line of people waiting at a bank machine • Collection of documents sent to a shared printer Note • Items are removed from a queue in the same order as they were inserted • it is not legal to access the elements in the middle of the queue!
  • 5. Queue Errors 1. Underflow – occurs when trying to Dequeue (or Front at) an empty queue 2. Overflow – occurs when trying to Enqueue onto an already full queue.
  • 6. Uses of Queues in Computing Queue is useful for any for any kind of problem involving FIFO data 1. printer queue 2. keyboard input buffer 3. GUI event queue 4. in simulation studies, where the goal is to reduce waiting times: − optimize the flow of traffic at a traffic light − determine number of cashiers to have on duty at a grocery store at different times of day.
  • 7. Implementation of Queue ADT 1. Array implementation of Queue • The entire queue is represented by an array together with two external “pointers” to keep track of the front and rear. • Suitable for applications in which the maximum queue size is known ahead of time. front Index prior the front element rear Index of the rear (last) element Both pointers are initially set to -1 (i.e. point before the first cell of the array.
  • 8. Code for adding an element to the rear [tail] of the queue
  • 9. Code for removing an element from the front of the queue.
  • 10. Code for determining whether the queue is empty
  • 11. Code for determining whether the queue is full
  • 12. Code for retrieving the element at the front[head] of the queue
  • 13. Code for making the queue empty
  • 14. Implementation of Queue ADT 1. Linked List implementation of Queue • The entire queue is represented by a linked list of nodes together with a pointer to the first node of the linked list (front) and a pointer to the end of the linked list (rear). • Suitable for applications in which the maximum queue size is not known beforehand. Note ▪ With a linked-list representation, overflow will not happen (unless you exhaust memory, which is another kind of problem) ▪ Underflow can happen, and should be handled.
  • 15. Code for adding an element to the rear [tail] of the queue
  • 16. Code for removing an element from the front of the queue.
  • 17. Code for determining whether the queue is empty
  • 18. Code for retrieving the element at the front[head] of the queue
  • 19. Code for making the queue empty