SlideShare a Scribd company logo
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

PPTX
Queues
PPTX
DS10-QUEUE0000000000000000000000000000000000000.pptx
PPTX
Queue types of queue and algorithms and queue
PPT
The Queue in Data structure and algorithm
PPT
Data Structures 2
PPTX
queue.pptx
Queues
DS10-QUEUE0000000000000000000000000000000000000.pptx
Queue types of queue and algorithms and queue
The Queue in Data structure and algorithm
Data Structures 2
queue.pptx

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

PPT
Queue data structure
PPTX
QUEUE in data-structure (classification, working procedure, Applications)
PPTX
stacks and queues for public
PPTX
Data structure and algorithm using java
PPT
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
PPT
Queue AS an ADT (Abstract Data Type)
PPTX
Data Structures in C
PDF
DSJ_Unit I & II.pdf
PPT
ds 1 Introduction to Data Structures.ppt
PPTX
Stack_and_Queue_Presentation_Final (1).pptx
PPTX
Stack_and_Queue_Presentation_Final (1).pptx
PPT
Data structures
PPTX
Understanding the Concepts and Applications of Stack and Queue
PDF
Lesson 3 - Stack ADT.pdf
PPT
Queue Data Structure
PPTX
UNIT-2.pptx
PPTX
Introduction to data structures and its types
PPTX
stack.pptx
PPTX
Data structures and algorithms
PPTX
STACK AND QUEUES APPLICATIONS, INFIX TO POST FIX
Queue data structure
QUEUE in data-structure (classification, working procedure, Applications)
stacks and queues for public
Data structure and algorithm using java
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
Queue AS an ADT (Abstract Data Type)
Data Structures in C
DSJ_Unit I & II.pdf
ds 1 Introduction to Data Structures.ppt
Stack_and_Queue_Presentation_Final (1).pptx
Stack_and_Queue_Presentation_Final (1).pptx
Data structures
Understanding the Concepts and Applications of Stack and Queue
Lesson 3 - Stack ADT.pdf
Queue Data Structure
UNIT-2.pptx
Introduction to data structures and its types
stack.pptx
Data structures and algorithms
STACK AND QUEUES APPLICATIONS, INFIX TO POST FIX
Ad

Recently uploaded (20)

PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
Cell Types and Its function , kingdom of life
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
master seminar digital applications in india
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Cell Structure & Organelles in detailed.
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Complications of Minimal Access Surgery at WLH
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Cell Types and Its function , kingdom of life
PPH.pptx obstetrics and gynecology in nursing
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
master seminar digital applications in india
Abdominal Access Techniques with Prof. Dr. R K Mishra
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
2.FourierTransform-ShortQuestionswithAnswers.pdf
RMMM.pdf make it easy to upload and study
VCE English Exam - Section C Student Revision Booklet
Microbial diseases, their pathogenesis and prophylaxis
102 student loan defaulters named and shamed – Is someone you know on the list?
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Cell Structure & Organelles in detailed.
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Complications of Minimal Access Surgery at WLH
Ad

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