SlideShare a Scribd company logo
2
Most read
3
Most read
7
Most read
5.Queue
Definition of Queue
• A Queue is an ordered collection of items in
which items are deleted from one end called
the front and items are inserted from other
end called rear.
• The elements are inserted and deleted in FIFO
manner.
Front=-1 , Rear=-1
Queue
Types of Queue
1. Circular Queue.
2. Priority Queue.
3. DeQue
4
Drawback of Linear Queue
• Once the queue is full, even though few elements from the front are deleted and
some occupied space is relieved, it is not possible to add anymore new elements,
as the rear has already reached the Queue’s rear most position.
Circular Queue
• This queue is not linear but circular.
• Its structure can be like the following figure:
Figure: Circular Queue having
Rear = 5 and Front = 0
• In circular queue, once the Queue is full the
"First" element of the Queue becomes the
"Rear" most element, if and only if the "Front"
has moved forward. otherwise it will again be
a "Queue overflow" state.
5
Example: Consider the following circular queue with N = 5.
1. Initially, Rear = 0, Front = 0.
2. Insert 10, Rear = 1, Front = 1.
3. Insert 50, Rear = 2, Front = 1.
4. Insert 20, Rear = 3, Front = 0.
5. Insert 70, Rear = 4, Front = 1.
6. Delete front, Rear = 4, Front = 2.
Rear
Rear
Rear
Rear
Rear
Front
Front
Front
Front
Front
Front=0
Rear=0
6
7. Insert 100, Rear = 5, Front = 2.
8. Insert 40, Rear = 1, Front = 2.
9. Insert 140, Rear = 1, Front = 2.
As Front = Rear + 1, so Queue overflow.
10. Delete front, Rear = 1, Front = 3.
Front
Rear
FrontRear
Rear
Rear
Front
Front
11. Delete front, Rear = 1, Front = 4.
12. Delete front, Rear = 1, Front = 5.
Rear
Rear
Front
Front
OPERATIONS AND ALGORITHMS OF CIRCULAR QUEUE:
1. Insert Operation:
Step 1: [Check for the Overflow]
If front = 1 and rear = n
Output “Overflow” and return
Step 2: [Insert element in the queue.]
Else if front = 0
front = 1
rear = 1
Q [rear] = value
Step 3: [Check if the rear at the end of the queue]
Else if rear = n
rear = 1
Q [rear] = value
Step 4: [insert the element]
Else
Rear = rear + 1
Q [rear] = value
Step 5: return
2. Delete Operation:
Step 1: [Check for underflow]
If front = 0
Output “Underflow” and return
Step 2: [Remove the element]
Value = Q [front]
Step 3: [Check whether the queue is empty or not]
If front = rear
front = 0
rear = 0
Step 4: [Check the front pointer position]
Else if front = n
front = 1
Else
front = front + 1
Step 5: [Return the removed element]
Return [value]
Priority Queues
• A Priority queue is a collection of elements
where each elements is assigned a priority.
1. An element of higher priority is processed
first.
2. Two elements with the same priority are
processed according to the order in which
they are added to queue.
e.g. Job Scheduling by OS.
• But should follow the FIFO concept.
• It can be a Ascending priority Queue or
Descending priority queue.
DEQues (Double Ended Queue)
• A Deque is a queue in which elements can be
inserted or deleted from any end. but not in
the middle.
• Four operations are possible on Deque.
1. Insert from front.
2. Insert from rear.
3. Delete from Front.
4. Delete from rear.
Reversing a stack using queue
1. Pop value from the stack.
2. Add that value to the queue.
3. Repeat step 1. till stack is not empty.
4. Delete a value from the queue and push it in
the same stack.
5. Repeat step 4. till queue is not empty.
Queue

More Related Content

PPT
Queue Data Structure
PPTX
PPT
Selection sort
PPTX
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
PPSX
PDF
Expression trees
PPTX
Doubly Linked List
PPTX
Queue in Data Structure
Queue Data Structure
Selection sort
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Expression trees
Doubly Linked List
Queue in Data Structure

What's hot (20)

PPT
Queue data structure
PPTX
Circular Queue data structure
PPTX
Different types of Linked list.
PPTX
PPTX
Binary Tree in Data Structure
PPTX
Linked list
PPTX
Infix to postfix conversion
PPTX
Stack & Queue using Linked List in Data Structure
PPTX
Queue - Data Structure - Notes
PPTX
Data Structures - Lecture 9 [Stack & Queue using Linked List]
PDF
Queue as data_structure
PPSX
Data structure stack&queue basics
PPTX
Stacks IN DATA STRUCTURES
PDF
Binary search tree operations
PDF
Array data structure
PPTX
Bubble sort | Data structure |
PPTX
STACKS IN DATASTRUCTURE
PPT
Doubly linked list
PPTX
Tree Traversal
PPTX
Priority queue in DSA
Queue data structure
Circular Queue data structure
Different types of Linked list.
Binary Tree in Data Structure
Linked list
Infix to postfix conversion
Stack & Queue using Linked List in Data Structure
Queue - Data Structure - Notes
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Queue as data_structure
Data structure stack&queue basics
Stacks IN DATA STRUCTURES
Binary search tree operations
Array data structure
Bubble sort | Data structure |
STACKS IN DATASTRUCTURE
Doubly linked list
Tree Traversal
Priority queue in DSA
Ad

Viewers also liked (20)

PPTX
Queue Data Structure (w/ php egs)
PPT
Queue Data Structure
PPTX
Queue
PPT
PPT
23 stacks-queues-deques
PPTX
stack
PPTX
Ppt presentation of queues
PPT
Notes DATA STRUCTURE - queue
PPT
DATA STRUCTURES
PPTX
Lists, queues and stacks
PDF
PDF
Dsa circular queue
PPT
Stack & queues
PDF
computer notes - Priority queue
PPT
23 priority queue
PPT
Circular queues
PPT
Stack & queue
PPT
Heaps & priority queues
PPTX
Stack and queue
Queue Data Structure (w/ php egs)
Queue Data Structure
Queue
23 stacks-queues-deques
stack
Ppt presentation of queues
Notes DATA STRUCTURE - queue
DATA STRUCTURES
Lists, queues and stacks
Dsa circular queue
Stack & queues
computer notes - Priority queue
23 priority queue
Circular queues
Stack & queue
Heaps & priority queues
Stack and queue
Ad

Similar to Queue (20)

PPTX
08_Queues.pptx showing how que works given vertex
PPT
Stacks and Queues concept in Data Structures
PPT
PPTX
Detalied information of queue
PPT
cp264_lecture18_queue.ppt
PPTX
My lectures circular queue
PPTX
RPT_02_B_Queue presentation for FE students
PPTX
apllicationsof queffffffffffffffffffffffffffffue.pptx
PPT
Data structure.ppt
PPT
intr_qyyuujjjjjjjkkkkkkkkkkkkkjkueue.ppt
PPT
10994103.ppt
PPTX
PDF
PPTX
queue & its applications
PPT
Lecture three of datat structures ,.The Queue-ds.ppt
PPTX
fdfdfdsfadsfsfdsfsffggfdgdgreddsfewdcedrdfe
PPTX
queue_final.pptx
PPTX
Module 2 ppt.pptx
08_Queues.pptx showing how que works given vertex
Stacks and Queues concept in Data Structures
Detalied information of queue
cp264_lecture18_queue.ppt
My lectures circular queue
RPT_02_B_Queue presentation for FE students
apllicationsof queffffffffffffffffffffffffffffue.pptx
Data structure.ppt
intr_qyyuujjjjjjjkkkkkkkkkkkkkjkueue.ppt
10994103.ppt
queue & its applications
Lecture three of datat structures ,.The Queue-ds.ppt
fdfdfdsfadsfsfdsfsffggfdgdgreddsfewdcedrdfe
queue_final.pptx
Module 2 ppt.pptx

Recently uploaded (20)

PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Insiders guide to clinical Medicine.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Pre independence Education in Inndia.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
Basic Mud Logging Guide for educational purpose
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Insiders guide to clinical Medicine.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Pre independence Education in Inndia.pdf
RMMM.pdf make it easy to upload and study
PPH.pptx obstetrics and gynecology in nursing
TR - Agricultural Crops Production NC III.pdf
Sports Quiz easy sports quiz sports quiz
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Cell Structure & Organelles in detailed.
Basic Mud Logging Guide for educational purpose
Computing-Curriculum for Schools in Ghana
Final Presentation General Medicine 03-08-2024.pptx
Microbial disease of the cardiovascular and lymphatic systems
FourierSeries-QuestionsWithAnswers(Part-A).pdf
01-Introduction-to-Information-Management.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf

Queue

  • 2. Definition of Queue • A Queue is an ordered collection of items in which items are deleted from one end called the front and items are inserted from other end called rear. • The elements are inserted and deleted in FIFO manner. Front=-1 , Rear=-1 Queue
  • 3. Types of Queue 1. Circular Queue. 2. Priority Queue. 3. DeQue
  • 4. 4 Drawback of Linear Queue • Once the queue is full, even though few elements from the front are deleted and some occupied space is relieved, it is not possible to add anymore new elements, as the rear has already reached the Queue’s rear most position. Circular Queue • This queue is not linear but circular. • Its structure can be like the following figure: Figure: Circular Queue having Rear = 5 and Front = 0 • In circular queue, once the Queue is full the "First" element of the Queue becomes the "Rear" most element, if and only if the "Front" has moved forward. otherwise it will again be a "Queue overflow" state.
  • 5. 5 Example: Consider the following circular queue with N = 5. 1. Initially, Rear = 0, Front = 0. 2. Insert 10, Rear = 1, Front = 1. 3. Insert 50, Rear = 2, Front = 1. 4. Insert 20, Rear = 3, Front = 0. 5. Insert 70, Rear = 4, Front = 1. 6. Delete front, Rear = 4, Front = 2. Rear Rear Rear Rear Rear Front Front Front Front Front Front=0 Rear=0
  • 6. 6 7. Insert 100, Rear = 5, Front = 2. 8. Insert 40, Rear = 1, Front = 2. 9. Insert 140, Rear = 1, Front = 2. As Front = Rear + 1, so Queue overflow. 10. Delete front, Rear = 1, Front = 3. Front Rear FrontRear Rear Rear Front Front 11. Delete front, Rear = 1, Front = 4. 12. Delete front, Rear = 1, Front = 5. Rear Rear Front Front
  • 7. OPERATIONS AND ALGORITHMS OF CIRCULAR QUEUE: 1. Insert Operation: Step 1: [Check for the Overflow] If front = 1 and rear = n Output “Overflow” and return Step 2: [Insert element in the queue.] Else if front = 0 front = 1 rear = 1 Q [rear] = value Step 3: [Check if the rear at the end of the queue] Else if rear = n rear = 1 Q [rear] = value Step 4: [insert the element] Else Rear = rear + 1 Q [rear] = value Step 5: return
  • 8. 2. Delete Operation: Step 1: [Check for underflow] If front = 0 Output “Underflow” and return Step 2: [Remove the element] Value = Q [front] Step 3: [Check whether the queue is empty or not] If front = rear front = 0 rear = 0 Step 4: [Check the front pointer position] Else if front = n front = 1 Else front = front + 1 Step 5: [Return the removed element] Return [value]
  • 9. Priority Queues • A Priority queue is a collection of elements where each elements is assigned a priority. 1. An element of higher priority is processed first. 2. Two elements with the same priority are processed according to the order in which they are added to queue. e.g. Job Scheduling by OS.
  • 10. • But should follow the FIFO concept. • It can be a Ascending priority Queue or Descending priority queue.
  • 11. DEQues (Double Ended Queue) • A Deque is a queue in which elements can be inserted or deleted from any end. but not in the middle. • Four operations are possible on Deque. 1. Insert from front. 2. Insert from rear. 3. Delete from Front. 4. Delete from rear.
  • 12. Reversing a stack using queue 1. Pop value from the stack. 2. Add that value to the queue. 3. Repeat step 1. till stack is not empty. 4. Delete a value from the queue and push it in the same stack. 5. Repeat step 4. till queue is not empty.