SlideShare a Scribd company logo
Contents
Introduction
Operations on queue
Array representation of queues
Linked representation of queues
Types of queues
Circular queues
Deques
Priority queues
Application of queues
References
DATA STRUCTURE
A data structure is a particular way of
organizing data in a computer so that it can be
used efficiently.
Different kind of data structure suits for the
different kind of applications.
Data Structure
Linear
Array
Linked list
Stack
Queue
Primitive DS Non-Primitive DS
Non Linear
Tree
Graph
Integer
Float
Char
Pointers
• Queue is a linear data structure.
• It is used for temporary storage of data values.
• A new element is added at one end called rear
end.
• The existing elements deleted from the other
end called front end.
• First-in-First-out property.
34 12 53 61 9 23 42
front
rear
Operations on Queue
1.Insertion :
Placing an item in a queue is called “insertion or
enqueue”, which is done at the end of the queue
called “rear”.
Front
Rear
2.Deletion :
Removing an item from a queue is called
“deletion or dequeue” , which is done at the
other end of the queue called “front”.
Front
Rear
Array Representation of Queues
12 9 7 18
12 9 7 18 14
A[0] A[1] A[2] A[3] A[4]
QUEUE
front
rear
front
rearQueue after insertion of a new element
9 7 18 14
front rear
Queue after deletion of an element
Algorithm to insert an element in queue
STEP-1 IF REAR= MAX-1
write OVERFLOW
go to step 4
[end of if]
STEP-2 if REAR = -1
set FRONT=REAR= 0
else
set REAR = REAR+1
STEP-3 set QUEUE [ REAR ] = NUM
STEP-4 EXIT
INITIALLY
REAR = -1
FRONT =-1
Algorithm to delete an element from queue
STEP-1 If FRONT = -1 or FRONT > REAR
write UNDERFLOW
Else
set VAL = QUEUE [ FRONT ]
set FRONT = FRONT + 1
[end of if]
STEP-2 EXIT
Linked Representation of Queues
9 300 7 350 4 360 2 N
290 Front 300 350 360 rear
Linked queue
9 300 7 350 4 360 2 380
290 front 300 350 360 380 rear
5 N
Linked queue after inserting a node
7 350 4 360 2 380
380 rear
5 N
300 front 350 360
Linked queue after deleting a node
Front = 290
Rear = 360
Algorithm to insert an element in queue
using linked list
STEP-1 Allocate memory for the new node & name it as TEMP.
STEP-2 set TEMP data = NUM
set TEMP link = NULL
STEP-3 If FRONT = NULL
FRONT = REAR = TEMP
Else
REAR link = TEMP
REAR = TEMP
[ end of if]
STEP-4 EXIT
INITIALLY
FRONT=NULL
REAR=NULL
Algorithm to delete an element from queue
STEP-1 If FRONT = NULL
write underflow
go to step 3.
[end of if]
STEP-2 set TEMP = FRONT
FRONT = FRONT link
if FRONT = NULL
REAR = NULL
STEP-3 EXIT
Types of Queues
1. Deque
2. Circular Queue
3. Priority Queue
DEQUES
1.Deque stands for double ended queue.
2.Elements can be inserted or deleted at
either end.
3. Also known as head-tail linked list.
34 12 53 61 9
insertion
deletion deletion
insertion
front rear
Types Of Deque
1.Input restricted deque:
34 12 53 61 9
deletion deletion
insertion
front rear
2. Output restricted deque:
34 12 53 61 9
insertion
deletion
insertion
front rear
CIRCULAR QUEUES
• Circular queue are used to remove the
drawback of simple queue.
• Both the front and the rear pointers wrap
around to the beginning of the array.
•It is also called as “Ring buffer”.
Algorithm to insert an element in queue
STEP-1 If FRONT = (REAR+1)%MAX
write OVERFLOW
go to step 4
[end of if]
STEP-2 If FRONT = -1
REAR = FRONT = 0
Else REAR = (REAR +1)%MAX
[ end of if ]
STEP-3 CQ[REAR] = NUM
STEP-4 EXIT
INITIALLY
FRONT= -1
REAR= 0
Algorithm to delete an element from queue
STEP-1 If FRONT = -1
write UNDERFLOW
go to step 3
[ end of if ]
STEP-2 If FRONT = REAR
FRONT = REAR= -1
Else
FRONT = (FRONT +1)%MAX
STEP-3 EXIT
PRIORITY QUEUE
1.It is collection of elements where elements are
stored according to the their priority levels.
2.Inserting and removing of elements from queue
is decided by the priority of the elements.
3. An element of the higher priority is processed
first.
4.Two element of same priority are processed on
first-come-first-served basis.
Example: Suppose you have a few assignment from
different subjects. Which assignment will you want
to do first?
subjects Due date priority
DSGT 15 OCT 4
DLD 6 OCT 2
CYB 4 OCT 1
DS 8 OCT 3
APPLICATIONS
 Real world applications
Cashier line in any store.
Waiting on hold for tech support.
people on an escalator.
Checkout at any book store.
Applications related to computer science:
1.When data is transferred asynchronously between
two processes. eg. IO Buffers.
2.When a resource is shared among multiple
consumers. Examples include CPU scheduling,
Disk Scheduling.
3.In recognizing palindrome.
4.In shared resources management.
5.Keyboard buffer.
6.Round robin scheduling.
7.Job scheduling.
8.Simulation
queue & its applications

More Related Content

What's hot

Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
Adam Mukharil Bachtiar
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Lovely Professional University
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
anooppjoseph
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application Tech_MX
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
03446940736
 
Stack
StackStack
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queueSenthil Kumar
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
topu93
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
Krish_ver2
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
Ninad Mankar
 
stack presentation
stack presentationstack presentation
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
Muhazzab Chouhadry
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
eShikshak
 
Stack
StackStack

What's hot (20)

Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Linked List
Linked ListLinked List
Linked List
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
 
Stack
StackStack
Stack
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
stack presentation
stack presentationstack presentation
stack presentation
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Heaps
HeapsHeaps
Heaps
 
Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Stack
StackStack
Stack
 
Stack
StackStack
Stack
 

Similar to queue & its applications

Queue
QueueQueue
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
MuhammadUmerIhtisham
 
Queue
QueueQueue
Queue
Raj Sarode
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
Rai University
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
Rai University
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
Rai University
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
Mandeep Singh
 
Queues
QueuesQueues
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
blessyboban92
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
SherinRappai
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
maneesh boddu
 
Queue
QueueQueue
10994103.ppt
10994103.ppt10994103.ppt
10994103.ppt
SushmaG48
 
05 queues
05 queues05 queues
05 queues
Rajan Gautam
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
Omprakash Chauhan
 
Queue
QueueQueue
cp264_lecture18_queue.ppt
cp264_lecture18_queue.pptcp264_lecture18_queue.ppt
cp264_lecture18_queue.ppt
ssuserff72e4
 

Similar to queue & its applications (20)

queue_final.pptx
queue_final.pptxqueue_final.pptx
queue_final.pptx
 
Queue
QueueQueue
Queue
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
Queue
QueueQueue
Queue
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
 
Queue
QueueQueue
Queue
 
Queues
QueuesQueues
Queues
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
Queue
QueueQueue
Queue
 
10994103.ppt
10994103.ppt10994103.ppt
10994103.ppt
 
05 queues
05 queues05 queues
05 queues
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Data structures
Data structuresData structures
Data structures
 
Queue
QueueQueue
Queue
 
cp264_lecture18_queue.ppt
cp264_lecture18_queue.pptcp264_lecture18_queue.ppt
cp264_lecture18_queue.ppt
 

Recently uploaded

Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABSDESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
itech2017
 
The Role of Electrical and Electronics Engineers in IOT Technology.pdf
The Role of Electrical and Electronics Engineers in IOT Technology.pdfThe Role of Electrical and Electronics Engineers in IOT Technology.pdf
The Role of Electrical and Electronics Engineers in IOT Technology.pdf
Nettur Technical Training Foundation
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Steel & Timber Design according to British Standard
Steel & Timber Design according to British StandardSteel & Timber Design according to British Standard
Steel & Timber Design according to British Standard
AkolbilaEmmanuel1
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
veerababupersonal22
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
Kamal Acharya
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 

Recently uploaded (20)

Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABSDESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
 
The Role of Electrical and Electronics Engineers in IOT Technology.pdf
The Role of Electrical and Electronics Engineers in IOT Technology.pdfThe Role of Electrical and Electronics Engineers in IOT Technology.pdf
The Role of Electrical and Electronics Engineers in IOT Technology.pdf
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Steel & Timber Design according to British Standard
Steel & Timber Design according to British StandardSteel & Timber Design according to British Standard
Steel & Timber Design according to British Standard
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 

queue & its applications

  • 1.
  • 2. Contents Introduction Operations on queue Array representation of queues Linked representation of queues Types of queues Circular queues Deques Priority queues Application of queues References
  • 3. DATA STRUCTURE A data structure is a particular way of organizing data in a computer so that it can be used efficiently. Different kind of data structure suits for the different kind of applications.
  • 4. Data Structure Linear Array Linked list Stack Queue Primitive DS Non-Primitive DS Non Linear Tree Graph Integer Float Char Pointers
  • 5. • Queue is a linear data structure. • It is used for temporary storage of data values. • A new element is added at one end called rear end. • The existing elements deleted from the other end called front end. • First-in-First-out property. 34 12 53 61 9 23 42 front rear
  • 6. Operations on Queue 1.Insertion : Placing an item in a queue is called “insertion or enqueue”, which is done at the end of the queue called “rear”. Front Rear
  • 7. 2.Deletion : Removing an item from a queue is called “deletion or dequeue” , which is done at the other end of the queue called “front”. Front Rear
  • 8. Array Representation of Queues 12 9 7 18 12 9 7 18 14 A[0] A[1] A[2] A[3] A[4] QUEUE front rear front rearQueue after insertion of a new element 9 7 18 14 front rear Queue after deletion of an element
  • 9. Algorithm to insert an element in queue STEP-1 IF REAR= MAX-1 write OVERFLOW go to step 4 [end of if] STEP-2 if REAR = -1 set FRONT=REAR= 0 else set REAR = REAR+1 STEP-3 set QUEUE [ REAR ] = NUM STEP-4 EXIT INITIALLY REAR = -1 FRONT =-1
  • 10. Algorithm to delete an element from queue STEP-1 If FRONT = -1 or FRONT > REAR write UNDERFLOW Else set VAL = QUEUE [ FRONT ] set FRONT = FRONT + 1 [end of if] STEP-2 EXIT
  • 11. Linked Representation of Queues 9 300 7 350 4 360 2 N 290 Front 300 350 360 rear Linked queue 9 300 7 350 4 360 2 380 290 front 300 350 360 380 rear 5 N Linked queue after inserting a node 7 350 4 360 2 380 380 rear 5 N 300 front 350 360 Linked queue after deleting a node Front = 290 Rear = 360
  • 12. Algorithm to insert an element in queue using linked list STEP-1 Allocate memory for the new node & name it as TEMP. STEP-2 set TEMP data = NUM set TEMP link = NULL STEP-3 If FRONT = NULL FRONT = REAR = TEMP Else REAR link = TEMP REAR = TEMP [ end of if] STEP-4 EXIT INITIALLY FRONT=NULL REAR=NULL
  • 13. Algorithm to delete an element from queue STEP-1 If FRONT = NULL write underflow go to step 3. [end of if] STEP-2 set TEMP = FRONT FRONT = FRONT link if FRONT = NULL REAR = NULL STEP-3 EXIT
  • 14. Types of Queues 1. Deque 2. Circular Queue 3. Priority Queue
  • 15. DEQUES 1.Deque stands for double ended queue. 2.Elements can be inserted or deleted at either end. 3. Also known as head-tail linked list. 34 12 53 61 9 insertion deletion deletion insertion front rear
  • 16. Types Of Deque 1.Input restricted deque: 34 12 53 61 9 deletion deletion insertion front rear 2. Output restricted deque: 34 12 53 61 9 insertion deletion insertion front rear
  • 17. CIRCULAR QUEUES • Circular queue are used to remove the drawback of simple queue. • Both the front and the rear pointers wrap around to the beginning of the array. •It is also called as “Ring buffer”.
  • 18. Algorithm to insert an element in queue STEP-1 If FRONT = (REAR+1)%MAX write OVERFLOW go to step 4 [end of if] STEP-2 If FRONT = -1 REAR = FRONT = 0 Else REAR = (REAR +1)%MAX [ end of if ] STEP-3 CQ[REAR] = NUM STEP-4 EXIT INITIALLY FRONT= -1 REAR= 0
  • 19. Algorithm to delete an element from queue STEP-1 If FRONT = -1 write UNDERFLOW go to step 3 [ end of if ] STEP-2 If FRONT = REAR FRONT = REAR= -1 Else FRONT = (FRONT +1)%MAX STEP-3 EXIT
  • 20. PRIORITY QUEUE 1.It is collection of elements where elements are stored according to the their priority levels. 2.Inserting and removing of elements from queue is decided by the priority of the elements. 3. An element of the higher priority is processed first. 4.Two element of same priority are processed on first-come-first-served basis.
  • 21. Example: Suppose you have a few assignment from different subjects. Which assignment will you want to do first? subjects Due date priority DSGT 15 OCT 4 DLD 6 OCT 2 CYB 4 OCT 1 DS 8 OCT 3
  • 22. APPLICATIONS  Real world applications Cashier line in any store. Waiting on hold for tech support. people on an escalator. Checkout at any book store.
  • 23. Applications related to computer science: 1.When data is transferred asynchronously between two processes. eg. IO Buffers. 2.When a resource is shared among multiple consumers. Examples include CPU scheduling, Disk Scheduling. 3.In recognizing palindrome. 4.In shared resources management. 5.Keyboard buffer. 6.Round robin scheduling. 7.Job scheduling. 8.Simulation