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

What's hot (20)

Terminology of tree
Terminology of treeTerminology of tree
Terminology of tree
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
 
Queues
QueuesQueues
Queues
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data Structure
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Arrays
ArraysArrays
Arrays
 
single linked list
single linked listsingle linked list
single linked list
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
 
Linked list
Linked listLinked list
Linked list
 
Stack
StackStack
Stack
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Sorting
SortingSorting
Sorting
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Queues
QueuesQueues
Queues
 
Linked list
Linked listLinked list
Linked list
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
 

Similar to queue & its applications

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
 
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
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 

Recently uploaded

result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
Tonystark477637
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 

Recently uploaded (20)

UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 

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