Subject : Data Structures
Topic : Queue
Queue
• Queue is Linear Data Structure
• It follows First In First Out(FIFO) principal
• It has two pointers front and rear
e.g.:
10 20 30 40 50
A[0] A[1] A[2] A[3] A[4]
Insertion
(ENQUEUE)
Deletion
(DEQUEUE)
Operations on Queue
Insertion:
Algorithm:
Step 1: If REAR = MAX – 1 then
Write “Queue is Overflow”
Goto step 4
[End of IF]
Step 2: IF FRONT=-1 and REAR=-1
SET FRONT=REAR=0
ELSE
SET REAR=REAR+1
[END OF IF]
Step 3: SET QUEUE [REAR] = NUM
Step 4: EXIT
Example of Insertion in Queue
A[0] A[1] A[2] A[3] A[4]
F=R=(-1)
10
A[0] A[1] A[2] A[3] A[4]
F=R=0
10 20
F=0 R=1
A[0] A[1] A[2] A[3] A[4]
Operations on Queue
Deletion:
Algorithm:
Step 1: IF FRONT = -1 OR FRONT>REAR
Write “Queue is Underflow”
ELSE
SET VAL=QUEUE [FRONT]
FRONT = FRONT + 1
[END OF IF]
Step 2: EXIT
Example of Deletion in Queue
10 20
A[0] A[1] A[2] A[3] A[4]
20
A[0] A[1] A[2] A[3] A[4]
F=R=1
F=0 R=1
Types Of Queue
1. Circular Queue
2. Priority Queue
3. Deque
4. Multiple Queue
Circular Queue
Why Circular Queue is needed?
• Problem:
– Wastage of memory in standard queue in DEQUEUE
operation
What is Circular Queue?
• The Arrangement of the elements Q[0], Q[1],
...,Q[n] in a circular fashion with Q[1]
following Q[n] is called Circular Queue.
• The last node is connected to first node to
make a circle.
• Initially, Both Front and Rear pointers points
to the beginning of the array.
• It is also known as “Ring Buffer”.
• e.g.:
Q[0]
Q[1]
Q[2]Q[3]
Q[4]
Q[5]
Q[6] Q[7]
F=R=Q[0]
Operations on Circular Queue
Insertion:
Algorithm:
Step 1: IF FRONT=0 and REAR=MAX-1 Then
Write “Overflow”
Goto Step 4
[END OF IF]
Step 2: IF FRONT = REAR=-1 then
SET FRONT=REAR=0
ELSE IF REAR=MAX-1 and FRONT!=0
SET REAR=0
ELSE
SET REAR=REAR+1
[END OF IF]
Step 3: SET QUEUE[REAR]=VAL
Step 4: EXIT
F=Q[0]
e.g.:
R=Q[7]
Q[0]
Q[1]
Q[2]Q[3]
Q[4]
Q[5]
Q[6] Q[7]
5
10
1520
25
30
35 40
Queue is full(Overflow)
Q[0]
Q[1]
Q[2]Q[3]
Q[4]
Q[5]
Q[6] Q[7]
F=R=Q[0]
e.g.:
If F=R=-1 then F=R=0
2
e.g.: (cond..)
F=Q[1]
e.g.: (cond..)
R=Q[7]Q[7]
Q[0]
Q[1]Q[2]
Q[3]
Q[4]
Q[5] Q[6]
1520
25
30
35 40
If REAR=MAX-1 and FRONT!=0
45
F=Q[0]
e.g.: (cond..)
Q[0]
Q[1]
Q[2]Q[3]
Q[4]
Q[5]
Q[6] Q[7]
5
10
R=Q[1]
Rear=Rear+1
Operations on Circular Queue
Deletion:
Algorithm:
Step 1: If FRONT = -1 then
Write ("Circular Queue Underflow“)
GOTO Step 4
Step 2: SET VAL=QUEUE[FRONT]
Step 3: If FRONT = REAR then
SET FRONT=REAR=-1
ELSE
IF FRONT=MAX-1
SET FRONT=0
ELSE
SET FRONT=FRONT+1
[END OF IF]
[END OF IF]
Step 4: EXIT
Q[0]
Q[1]
Q[2]Q[3]
Q[4]
Q[5]
Q[6] Q[7]
F=R=-1
e.g.:
Queue is Empty(Underflow)
Q[0]
Q[1]
Q[2]Q[3]
Q[4]
Q[5]
Q[6] Q[7]
F=R=Q[0]
e.g.:
If F=R=0 then F=R=-1
5
F=Q[1]
e.g.: (cond..)
R=Q[7]Q[7]
Q[0]
Q[1]Q[2]
Q[3]
Q[4]
Q[5] Q[6]
1520
25
30
35 40
45
If Front=MAX-1 then Front=0
F=Q[4]
e.g.: (cond..)
R=Q[1]Q[1]
Q[2]
Q[3]Q[4]
Q[5]
Q[6]
Q[7] Q[8]
20
25
30
35 40
Front=Front+1
45
Priority Queue
Priority Queue
• In priority queue, each element is assigned a
priority.
• Priority of an element determines the order in
which the elements will be processed.
• Rules:
1. An element with higher priority will processed
before an element with a lower priority.
2. Two elements with the same priority are
processed on a First Come First Serve basis.
Types of Priority Queue
1. Ascending Priority Queue
In this type of priority queue, elements can be
inserted into any order but only the smallest
element can be removed.
2. Descending Priority Queue
In this type of priority queue, elements can be
inserted into any order but only the largest element
can be removed.
Array Representation of Priority Queue
Insertion Operation:
• While inserting elements in priority queue we
will add it at the appropriate position
depending on its priority
• It is inserted in such a way that the elements
are always ordered either in Ascending or
descending sequence
Array Representation of Priority Queue
15 10
20 15 10
25 15 13 10
A[0] A[1] A[2] A[3] A[4]
Front Rear
A[0] A[1] A[2] A[3] A[4]
Front Rear
A[0] A[1] A[2] A[3] A[4]
Front Rear
Array Representation of Priority Queue
Deletion Operation:
• While deletion, the element at the front is
always deleted.
Array Representation of Priority Queue
20 15 13 10
15 13 10
13 10
A[0] A[1] A[2] A[3] A[4]
Front Rear
A[0] A[1] A[2] A[3] A[4]
Front Rear
A[0] A[1] A[2] A[3] A[4]
Front Rear
Double Ended Queue
Deque / Double Ended Queue
• A list in which elements can be inserted or
deleted either end
• It is also known as “Head-Tail Linked List”
• It has two pointers LEFT and RIGHT, which
point to either end of the deque.
• Dequeue can be implemented using Circular
Array or a Circular doubly linked list where
Dequeue[n-1] is followed by Dequeue[0]
Types of Deque
• Input Restricted Deque:-
In this dequeue, insertion can be done only at one of
the end, while deletion can be done from both ends.
• Output Restricted Deque:-
In this dequeue, deletion can be done only at
one of the ends, while insertions can be done
on both ends
Queue in Data Structure

More Related Content

PPTX
Queue ppt
PDF
Introduction to Operating Systems
PPTX
STACKS IN DATASTRUCTURE
PPTX
Presentation on queue
PPTX
C Programming: Control Structure
PPTX
Graph in data structure
PDF
Linked list implementation of Queue
PDF
Image Segmentation (Digital Image Processing)
Queue ppt
Introduction to Operating Systems
STACKS IN DATASTRUCTURE
Presentation on queue
C Programming: Control Structure
Graph in data structure
Linked list implementation of Queue
Image Segmentation (Digital Image Processing)

What's hot (20)

PDF
Applications of stack
PPTX
Priority Queue in Data Structure
PDF
PPTX
PPTX
stack & queue
PPTX
Linked List
PPTX
Recursion
PPT
Data Structure and Algorithms Binary Search Tree
PPTX
Binary Search Tree
PPTX
Stacks IN DATA STRUCTURES
PDF
sparse matrix in data structure
PPT
PPT
SEARCHING AND SORTING ALGORITHMS
PDF
Array data structure
PPT
Queue AS an ADT (Abstract Data Type)
PPTX
Linked list
PPTX
Hashing
PPTX
linked list in data structure
PPSX
Data Structure (Queue)
PPTX
Binary Tree in Data Structure
Applications of stack
Priority Queue in Data Structure
stack & queue
Linked List
Recursion
Data Structure and Algorithms Binary Search Tree
Binary Search Tree
Stacks IN DATA STRUCTURES
sparse matrix in data structure
SEARCHING AND SORTING ALGORITHMS
Array data structure
Queue AS an ADT (Abstract Data Type)
Linked list
Hashing
linked list in data structure
Data Structure (Queue)
Binary Tree in Data Structure
Ad

Similar to Queue in Data Structure (20)

PPT
Queues & ITS TYPES
PPT
PPT
queue (1).ppt queue notes and ppt in Data Structures
PPTX
PDF
Polynomialmotilalanehrunationalinstitute.pdf
PPTX
Detalied information of queue
PPTX
Queue - Data Structure - Notes
PDF
Queues-and-CQueue-Implementation
PPTX
apllicationsof queffffffffffffffffffffffffffffue.pptx
PPTX
queue_final.pptx
PPTX
queue & its applications
PPTX
4. Queues in Data Structure
PPTX
Lecture 6 data structures and algorithms
PPT
Unit 2 linked list and queues
PPTX
6.queue
PPTX
Lecture 7 data structures and algorithms
PPTX
Stack.pptx
PPTX
fdfdfdsfadsfsfdsfsffggfdgdgreddsfewdcedrdfe
Queues & ITS TYPES
queue (1).ppt queue notes and ppt in Data Structures
Polynomialmotilalanehrunationalinstitute.pdf
Detalied information of queue
Queue - Data Structure - Notes
Queues-and-CQueue-Implementation
apllicationsof queffffffffffffffffffffffffffffue.pptx
queue_final.pptx
queue & its applications
4. Queues in Data Structure
Lecture 6 data structures and algorithms
Unit 2 linked list and queues
6.queue
Lecture 7 data structures and algorithms
Stack.pptx
fdfdfdsfadsfsfdsfsffggfdgdgreddsfewdcedrdfe
Ad

More from Janki Shah (9)

PPTX
Collections in .net technology (2160711)
PPTX
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
PPTX
File Management in Operating System
PPT
Addressing in Computer Networks
PPTX
Concurrency Control in Database Management System
PPTX
Number system in Digital Electronics
PPTX
Exception Handling in object oriented programming using C++
PPTX
Compiler in System Programming/Code Optimization techniques in System Program...
PPT
Sorting in Linear Time in Analysis & Design of Algorithm
Collections in .net technology (2160711)
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
File Management in Operating System
Addressing in Computer Networks
Concurrency Control in Database Management System
Number system in Digital Electronics
Exception Handling in object oriented programming using C++
Compiler in System Programming/Code Optimization techniques in System Program...
Sorting in Linear Time in Analysis & Design of Algorithm

Recently uploaded (20)

DOC
T Pandian CV Madurai pandi kokkaf illaya
PPTX
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
PPTX
Amdahl’s law is explained in the above power point presentations
PDF
Cryptography and Network Security-Module-I.pdf
PPTX
Software Engineering and software moduleing
PDF
UEFA_Carbon_Footprint_Calculator_Methology_2.0.pdf
PDF
AIGA 012_04 Cleaning of equipment for oxygen service_reformat Jan 12.pdf
PPTX
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
PDF
20250617 - IR - Global Guide for HR - 51 pages.pdf
PDF
Present and Future of Systems Engineering: Air Combat Systems
PDF
August 2025 - Top 10 Read Articles in Network Security & Its Applications
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PPTX
CONTRACTS IN CONSTRUCTION PROJECTS: TYPES
PPTX
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
PPTX
CN_Unite_1 AI&DS ENGGERING SPPU PUNE UNIVERSITY
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PDF
Unit I -OPERATING SYSTEMS_SRM_KATTANKULATHUR.pptx.pdf
PDF
electrical machines course file-anna university
PPTX
Principal presentation for NAAC (1).pptx
T Pandian CV Madurai pandi kokkaf illaya
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
Amdahl’s law is explained in the above power point presentations
Cryptography and Network Security-Module-I.pdf
Software Engineering and software moduleing
UEFA_Carbon_Footprint_Calculator_Methology_2.0.pdf
AIGA 012_04 Cleaning of equipment for oxygen service_reformat Jan 12.pdf
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
20250617 - IR - Global Guide for HR - 51 pages.pdf
Present and Future of Systems Engineering: Air Combat Systems
August 2025 - Top 10 Read Articles in Network Security & Its Applications
Management Information system : MIS-e-Business Systems.pptx
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
CONTRACTS IN CONSTRUCTION PROJECTS: TYPES
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
CN_Unite_1 AI&DS ENGGERING SPPU PUNE UNIVERSITY
distributed database system" (DDBS) is often used to refer to both the distri...
Unit I -OPERATING SYSTEMS_SRM_KATTANKULATHUR.pptx.pdf
electrical machines course file-anna university
Principal presentation for NAAC (1).pptx

Queue in Data Structure