SlideShare a Scribd company logo
Queue
• A Queue is a linear structure that follows a particular order
in which the operations are performed. The order is First In
First Out (FIFO). A good example of a queue is any queue of
consumers for a resource where the consumer that came
first is served first.
Characteristics of queue
•FIFO Principle – The first element added is the first to be removed.
•Linear Structure – Elements are arranged in a sequential, straight-line order.
•Dynamic or Fixed Size – Queues can be of fixed size (array) or dynamic size (linked list).
•Insertion at Rear – New elements are added at the rear end of the queue.
•Deletion at Front – Elements are removed from the front end of the queue.
•Overflow and Underflow – Overflow occurs when the queue is full, underflow when it’s empty.
Array representation of queue
• A queue is a linear data structure that follows FIFO principle and can
be implemented using linear array called QUEUE of size n. it uses two
important variables, FRONT and REAR, to manage and keep track of
the elements in the queue.
1. FRONT: holds the index of the front element in the queue, which is
the element to be removed next.
2. REAR: holds the index of the rear element in the queue, which is the
position where the next element will be inserted.
Initial state of queue
• Before any operations are performed, the queue is empty, and the
variables are initialized are initialized as follows:
1. REAR= -1 : indicates that no elements have been added to the
queue yet.
2. FRONT= 0: points to the position where the first element will be
processed.
Conditions for queue states
1. Queue is Empty: front == -1 && rear == -1
Both front and rear are set to -1 initially, indicating no elements in the
queue.
2. Queue Has One Element: front == rear
When there's only one element, both front and rear point to the same
index.
3. Queue is Full: rear == MAX - 1
In a fixed-size array queue, if rear reaches the last index of the array (MAX -
1), the queue is full and no more elements can be added (unless it's a
circular queue).
✅ Advantages of Array Representation of Queues
• Simple and easy to implement using basic array and pointers.
• Allows fast access to elements using array indices.
• Suitable when maximum queue size is known in advance.
❌ Disadvantages of Array Representation of Queues
• Fixed size makes it inflexible for dynamic data.
• Deleting elements leads to unused space unless shifted or circular queue is
used.
• Resizing the array requires copying all elements, which is time-consuming.
Linked List Representation of Queue
In the linked list representation of a queue, elements are stored in nodes,
and each node contains two parts:
Data: The actual value being stored.
Next Pointer: A reference to the next node in the queue (or null if it's the
last node).
Key Components:
Front Pointer: Points to the first node in the queue (the element to be
dequeued next).
Rear Pointer: Points to the last node in the queue (the element where the
next one will be added).
Advantages:
1. The size of the queue can grow or shrink dynamically without
wasting memory.
2. No unused space, as elements are added or removed as needed.
3. Insertion and deletion operations are efficient (O(1)) because only
pointers are adjusted.
Disadvantages:
1. Each element requires extra memory for the pointer/reference to the
next node.
2. More complex to implement compared to array-based queues.
3. Errors in pointer manipulation (e.g., `null` references) can lead to
bugs or memory issues.
Insert operation
Step 1: [overflow check]
if REAR = N-1
then write (“queue overflow”)
return
Step 2: [increment rear pointer]
REAR = REAR +1
Step 3: [insert the item]
Q[REAR] = item
Step 4: return.
Delete operation
Step1: [underflow check]
if(REAR == FRONT -1)
then write (“queue underflow”)
return
Step 2: [delete the item]
ITEM= Q[FRONT]
Step 3: if (FRONT == REAR) [when there is only one item]
FRONT= 0, REAR = -1
else
FRONT = FRONT +1
Step 4: return
Queue empty operation
Int Qempty()
{
if(REAR== FRONT-1)
return 1;
else
return 0;
}
Queue full operation(Qfull)
Int Qfull()
{
if(REAR == N-1)
return 1;
else
return 0;
}
Types of Queues:
There are five different types of queues:
1.Input Restricted Queue (this is a Simple Queue
2. Output Restricted Queue (this is also a Simple Queue)
3. Circular Queue
4. Double Ended Queue (Deque)
5. Priority Queue
1.Ascending Priority Queue
2.Descending Priority Queue
1. Circular Queue: Circular Queue is a linear data structure in
which the operations are performed based on FIFO (First In
First Out) principle and the last position is connected back to
the first position to make a circle. It is also called ‘Ring
Buffer’
2. Input restricted Queue: In this type of Queue, the input
can be taken from one side only(rear) and deletion of
elements can be done from both sides(front and rear). This
kind of Queue does not follow FIFO(first in first out). This
queue is used in cases where the consumption of the data
needs to be in FIFO order but if there is a need to remove the
recently inserted data for some reason and one such case can
be irrelevant data, performance issue, etc.
3. Output restricted Queue: In this type of Queue, the input
can be taken from both sides(rear and front) and the deletion
of the element can be done from only one side(front). This
queue is used in the case where the inputs have some priority
order to be executed and the input can be placed even in the
first place so that it is executed first.
4. Double ended Queue: Double Ended Queue is also a
Queue data structure in which the insertion and deletion
operations are performed at both the ends (front and rear).
That means, we can insert at both front and rear positions
and can delete from both front and rear positions. Since
Deque supports both stack and queue operations, it can be
used as both.
5. Priority Queue: A priority queue is a special type of queue in which each
element is associated with a priority and is served according to its priority.
There are two types of Priority Queues. They are:
1.Ascending Priority Queue: Element can be inserted arbitrarily but only
smallest element can be removed. For example, suppose there is an array
having elements 4, 2, 8 in the same order. So, while inserting the elements, the
insertion will be in the same sequence but while deleting, the order will be 2, 4,
8.
2.Descending priority Queue: Element can be inserted arbitrarily but only the
largest element can be removed first from the given Queue. For example,
suppose there is an array having elements 4, 2, 8 in the same order. So, while
inserting the elements, the insertion will be in the same sequence but while
deleting, the order will be 8, 4, 2.
Applications of Queue
CPU Scheduling
Queues are used in operating systems to manage the execution of processes, where processes are
scheduled to run in a FIFO order.
Printer Spooling
In printer queues, documents are arranged in a queue for printing, ensuring that they are printed in the order
they were sent.
Data Buffering
In data communication systems, queues are used to store data temporarily as it is being transferred
between different devices, like in network routers or IO devices.
Customer Service Systems
Queues are used in call centers or ticketing systems, where customers are served in the order of their
arrival.
Real-time Data Processing
Queues are used in real-time systems for processing tasks like in messaging systems or streaming data.
Handling Requests in Web Servers
Web servers use queues to handle incoming client requests and process them in the order they are
received.
Simulation Systems
Queues are commonly used in simulations like modeling customer checkout lines or airport security, where
entities are processed one after another.
Advantages of Queue
FIFO Ordering
Ensures that elements are processed in the order they arrive, making it predictable and fair.
Efficient for Task Scheduling
Ideal for scenarios where tasks or processes need to be executed in the order they are received, like
in CPU scheduling or print queues.
Real-time Data Handling
Useful in real-time systems where data needs to be processed as it arrives, such as in network
communication or buffer management.
Disadvantages of Queue
1.Fixed Size (for Array Implementation)
1. In array-based queues, the size is fixed, limiting the queue's capacity unless
dynamically resized.
2.Wasted Space
1. In array-based queues, once elements are dequeued, the space they
occupied can become wasted unless managed by techniques like circular
queues.
3.Slow Access to Elements
1. Unlike other data structures (e.g., arrays or linked lists), queue operations
(enqueue and dequeue) are the only direct operations, meaning random
access to specific elements is not possible.

More Related Content

PPT
The Queue in Data structure and algorithm
PPTX
DS UNIT2QUEUES.pptx
PPTX
DS10-QUEUE0000000000000000000000000000000000000.pptx
PPTX
Stack_and_Queue_Presentation_Final (1).pptx
PPTX
Stack_and_Queue_Presentation_Final (1).pptx
PPTX
GROUP2.pptxfdfffffffffffffffffffffffffffffffffffffffffff
PPT
Data Structures 2
PPTX
STACK AND QUEUES APPLICATIONS, INFIX TO POST FIX
The Queue in Data structure and algorithm
DS UNIT2QUEUES.pptx
DS10-QUEUE0000000000000000000000000000000000000.pptx
Stack_and_Queue_Presentation_Final (1).pptx
Stack_and_Queue_Presentation_Final (1).pptx
GROUP2.pptxfdfffffffffffffffffffffffffffffffffffffffffff
Data Structures 2
STACK AND QUEUES APPLICATIONS, INFIX TO POST FIX

Similar to Queue types of queue and algorithms and queue (20)

PPTX
queue.pptx
PPT
Queue AS an ADT (Abstract Data Type)
PPTX
Stack and Queue.pptx
PPTX
Understanding the Concepts and Applications of Stack and Queue
PPTX
VCE Unit 03vv.pptx
PDF
5-Queue-----------------------------in c++
PPT
Chapter 4.pptmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
PPT
queue data structures-linear data structure
PDF
9f556226-babd-4276-b964-371c6a5a77b9.pdf
PPTX
Queues
PDF
Lesson 4 - Queue ADT.pdf
PPT
Stacks and Queues concept in Data Structures
PPTX
DS ppt1.pptx.c programing. Engineering. Data structure
PPTX
Priority Queue in Data Structure
PPT
unit 5 stack & queue.ppt
PPTX
circular_queue.pptx
PPT
10994103.ppt
PPTX
Unit ii linear data structures
PPT
Data Structures
queue.pptx
Queue AS an ADT (Abstract Data Type)
Stack and Queue.pptx
Understanding the Concepts and Applications of Stack and Queue
VCE Unit 03vv.pptx
5-Queue-----------------------------in c++
Chapter 4.pptmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
queue data structures-linear data structure
9f556226-babd-4276-b964-371c6a5a77b9.pdf
Queues
Lesson 4 - Queue ADT.pdf
Stacks and Queues concept in Data Structures
DS ppt1.pptx.c programing. Engineering. Data structure
Priority Queue in Data Structure
unit 5 stack & queue.ppt
circular_queue.pptx
10994103.ppt
Unit ii linear data structures
Data Structures
Ad

Recently uploaded (20)

PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Cell Types and Its function , kingdom of life
PPTX
Cell Structure & Organelles in detailed.
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Classroom Observation Tools for Teachers
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Business Ethics Teaching Materials for college
PPTX
master seminar digital applications in india
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
RMMM.pdf make it easy to upload and study
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Anesthesia in Laparoscopic Surgery in India
Cell Types and Its function , kingdom of life
Cell Structure & Organelles in detailed.
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Supply Chain Operations Speaking Notes -ICLT Program
VCE English Exam - Section C Student Revision Booklet
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Classroom Observation Tools for Teachers
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Business Ethics Teaching Materials for college
master seminar digital applications in india
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
STATICS OF THE RIGID BODIES Hibbelers.pdf
Complications of Minimal Access Surgery at WLH
RMMM.pdf make it easy to upload and study
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Ad

Queue types of queue and algorithms and queue

  • 2. • A Queue is a linear structure that follows a particular order in which the operations are performed. The order is First In First Out (FIFO). A good example of a queue is any queue of consumers for a resource where the consumer that came first is served first.
  • 3. Characteristics of queue •FIFO Principle – The first element added is the first to be removed. •Linear Structure – Elements are arranged in a sequential, straight-line order. •Dynamic or Fixed Size – Queues can be of fixed size (array) or dynamic size (linked list). •Insertion at Rear – New elements are added at the rear end of the queue. •Deletion at Front – Elements are removed from the front end of the queue. •Overflow and Underflow – Overflow occurs when the queue is full, underflow when it’s empty.
  • 4. Array representation of queue • A queue is a linear data structure that follows FIFO principle and can be implemented using linear array called QUEUE of size n. it uses two important variables, FRONT and REAR, to manage and keep track of the elements in the queue. 1. FRONT: holds the index of the front element in the queue, which is the element to be removed next. 2. REAR: holds the index of the rear element in the queue, which is the position where the next element will be inserted.
  • 5. Initial state of queue • Before any operations are performed, the queue is empty, and the variables are initialized are initialized as follows: 1. REAR= -1 : indicates that no elements have been added to the queue yet. 2. FRONT= 0: points to the position where the first element will be processed.
  • 6. Conditions for queue states 1. Queue is Empty: front == -1 && rear == -1 Both front and rear are set to -1 initially, indicating no elements in the queue. 2. Queue Has One Element: front == rear When there's only one element, both front and rear point to the same index. 3. Queue is Full: rear == MAX - 1 In a fixed-size array queue, if rear reaches the last index of the array (MAX - 1), the queue is full and no more elements can be added (unless it's a circular queue).
  • 7. ✅ Advantages of Array Representation of Queues • Simple and easy to implement using basic array and pointers. • Allows fast access to elements using array indices. • Suitable when maximum queue size is known in advance. ❌ Disadvantages of Array Representation of Queues • Fixed size makes it inflexible for dynamic data. • Deleting elements leads to unused space unless shifted or circular queue is used. • Resizing the array requires copying all elements, which is time-consuming.
  • 8. Linked List Representation of Queue In the linked list representation of a queue, elements are stored in nodes, and each node contains two parts: Data: The actual value being stored. Next Pointer: A reference to the next node in the queue (or null if it's the last node). Key Components: Front Pointer: Points to the first node in the queue (the element to be dequeued next). Rear Pointer: Points to the last node in the queue (the element where the next one will be added).
  • 9. Advantages: 1. The size of the queue can grow or shrink dynamically without wasting memory. 2. No unused space, as elements are added or removed as needed. 3. Insertion and deletion operations are efficient (O(1)) because only pointers are adjusted. Disadvantages: 1. Each element requires extra memory for the pointer/reference to the next node. 2. More complex to implement compared to array-based queues. 3. Errors in pointer manipulation (e.g., `null` references) can lead to bugs or memory issues.
  • 10. Insert operation Step 1: [overflow check] if REAR = N-1 then write (“queue overflow”) return Step 2: [increment rear pointer] REAR = REAR +1 Step 3: [insert the item] Q[REAR] = item Step 4: return.
  • 11. Delete operation Step1: [underflow check] if(REAR == FRONT -1) then write (“queue underflow”) return Step 2: [delete the item] ITEM= Q[FRONT] Step 3: if (FRONT == REAR) [when there is only one item] FRONT= 0, REAR = -1 else FRONT = FRONT +1 Step 4: return
  • 12. Queue empty operation Int Qempty() { if(REAR== FRONT-1) return 1; else return 0; }
  • 13. Queue full operation(Qfull) Int Qfull() { if(REAR == N-1) return 1; else return 0; }
  • 14. Types of Queues: There are five different types of queues: 1.Input Restricted Queue (this is a Simple Queue 2. Output Restricted Queue (this is also a Simple Queue) 3. Circular Queue 4. Double Ended Queue (Deque) 5. Priority Queue 1.Ascending Priority Queue 2.Descending Priority Queue
  • 15. 1. Circular Queue: Circular Queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position to make a circle. It is also called ‘Ring Buffer’
  • 16. 2. Input restricted Queue: In this type of Queue, the input can be taken from one side only(rear) and deletion of elements can be done from both sides(front and rear). This kind of Queue does not follow FIFO(first in first out). This queue is used in cases where the consumption of the data needs to be in FIFO order but if there is a need to remove the recently inserted data for some reason and one such case can be irrelevant data, performance issue, etc.
  • 17. 3. Output restricted Queue: In this type of Queue, the input can be taken from both sides(rear and front) and the deletion of the element can be done from only one side(front). This queue is used in the case where the inputs have some priority order to be executed and the input can be placed even in the first place so that it is executed first.
  • 18. 4. Double ended Queue: Double Ended Queue is also a Queue data structure in which the insertion and deletion operations are performed at both the ends (front and rear). That means, we can insert at both front and rear positions and can delete from both front and rear positions. Since Deque supports both stack and queue operations, it can be used as both.
  • 19. 5. Priority Queue: A priority queue is a special type of queue in which each element is associated with a priority and is served according to its priority. There are two types of Priority Queues. They are: 1.Ascending Priority Queue: Element can be inserted arbitrarily but only smallest element can be removed. For example, suppose there is an array having elements 4, 2, 8 in the same order. So, while inserting the elements, the insertion will be in the same sequence but while deleting, the order will be 2, 4, 8. 2.Descending priority Queue: Element can be inserted arbitrarily but only the largest element can be removed first from the given Queue. For example, suppose there is an array having elements 4, 2, 8 in the same order. So, while inserting the elements, the insertion will be in the same sequence but while deleting, the order will be 8, 4, 2.
  • 20. Applications of Queue CPU Scheduling Queues are used in operating systems to manage the execution of processes, where processes are scheduled to run in a FIFO order. Printer Spooling In printer queues, documents are arranged in a queue for printing, ensuring that they are printed in the order they were sent. Data Buffering In data communication systems, queues are used to store data temporarily as it is being transferred between different devices, like in network routers or IO devices. Customer Service Systems Queues are used in call centers or ticketing systems, where customers are served in the order of their arrival. Real-time Data Processing Queues are used in real-time systems for processing tasks like in messaging systems or streaming data. Handling Requests in Web Servers Web servers use queues to handle incoming client requests and process them in the order they are received. Simulation Systems Queues are commonly used in simulations like modeling customer checkout lines or airport security, where entities are processed one after another.
  • 21. Advantages of Queue FIFO Ordering Ensures that elements are processed in the order they arrive, making it predictable and fair. Efficient for Task Scheduling Ideal for scenarios where tasks or processes need to be executed in the order they are received, like in CPU scheduling or print queues. Real-time Data Handling Useful in real-time systems where data needs to be processed as it arrives, such as in network communication or buffer management.
  • 22. Disadvantages of Queue 1.Fixed Size (for Array Implementation) 1. In array-based queues, the size is fixed, limiting the queue's capacity unless dynamically resized. 2.Wasted Space 1. In array-based queues, once elements are dequeued, the space they occupied can become wasted unless managed by techniques like circular queues. 3.Slow Access to Elements 1. Unlike other data structures (e.g., arrays or linked lists), queue operations (enqueue and dequeue) are the only direct operations, meaning random access to specific elements is not possible.