SlideShare a Scribd company logo
2
Most read
5
Most read
20
Most read
queue & its applications
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

PPT
Queue data structure
PPTX
Priority Queue in Data Structure
PPTX
Queue - Data Structure - Notes
PPTX
Queue in Data Structure
PPTX
PPSX
Data Structure (Queue)
PPTX
stack & queue
PPTX
Queue data structure
Priority Queue in Data Structure
Queue - Data Structure - Notes
Queue in Data Structure
Data Structure (Queue)
stack & queue

What's hot (20)

PPTX
Doubly Linked List
PPTX
Queue ppt
PPTX
Binary Tree in Data Structure
PPTX
Priority queue in DSA
PPTX
Tree - Data Structure
PPTX
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
PPTX
Linked List - Insertion & Deletion
PPTX
Double Linked List (Algorithm)
PPTX
Stack organization
PPTX
Arrays In C++
PPTX
heap Sort Algorithm
PPTX
Data structure - Graph
PPTX
Breadth First Search & Depth First Search
PPT
Queue Data Structure
PPTX
Stacks IN DATA STRUCTURES
PPTX
Bfs and Dfs
PDF
Binary search tree operations
PPTX
Stacks and Queue - Data Structures
PPTX
Selection sorting
PPTX
Circular link list.ppt
Doubly Linked List
Queue ppt
Binary Tree in Data Structure
Priority queue in DSA
Tree - Data Structure
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Linked List - Insertion & Deletion
Double Linked List (Algorithm)
Stack organization
Arrays In C++
heap Sort Algorithm
Data structure - Graph
Breadth First Search & Depth First Search
Queue Data Structure
Stacks IN DATA STRUCTURES
Bfs and Dfs
Binary search tree operations
Stacks and Queue - Data Structures
Selection sorting
Circular link list.ppt
Ad

Similar to queue & its applications (20)

PPTX
queue_final.pptx
PPTX
apllicationsof queffffffffffffffffffffffffffffue.pptx
PPTX
fdfdfdsfadsfsfdsfsffggfdgdgreddsfewdcedrdfe
PPT
Stacks and Queues concept in Data Structures
PPT
cp264_lecture18_queue.ppt
PPTX
Lecture 7 data structures and algorithms
PPTX
RPT_02_B_Queue presentation for FE students
PPTX
6.queue
PPT
10994103.ppt
PPTX
Queue
PPTX
PPTX
PPTX
Detalied information of queue
PPTX
Queue data structures and operation on data structures
PPT
Lecture three of datat structures ,.The Queue-ds.ppt
PPTX
Queues
PDF
LEC4-DS ALGO.pdf
queue_final.pptx
apllicationsof queffffffffffffffffffffffffffffue.pptx
fdfdfdsfadsfsfdsfsffggfdgdgreddsfewdcedrdfe
Stacks and Queues concept in Data Structures
cp264_lecture18_queue.ppt
Lecture 7 data structures and algorithms
RPT_02_B_Queue presentation for FE students
6.queue
10994103.ppt
Queue
Detalied information of queue
Queue data structures and operation on data structures
Lecture three of datat structures ,.The Queue-ds.ppt
Queues
LEC4-DS ALGO.pdf
Ad

Recently uploaded (20)

PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPT
Mechanical Engineering MATERIALS Selection
DOCX
573137875-Attendance-Management-System-original
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
web development for engineering and engineering
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Sustainable Sites - Green Building Construction
PPTX
Welding lecture in detail for understanding
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
Well-logging-methods_new................
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Embodied AI: Ushering in the Next Era of Intelligent Systems
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Lesson 3_Tessellation.pptx finite Mathematics
Mechanical Engineering MATERIALS Selection
573137875-Attendance-Management-System-original
Arduino robotics embedded978-1-4302-3184-4.pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Internet of Things (IOT) - A guide to understanding
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
web development for engineering and engineering
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Sustainable Sites - Green Building Construction
Welding lecture in detail for understanding
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Well-logging-methods_new................
Lecture Notes Electrical Wiring System Components
Operating System & Kernel Study Guide-1 - converted.pdf

queue & its applications

  • 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