1. Fundamental data structure
UNDER THE GUIDANCE OF :
HAMSA VAHENI
PRESENTED BY:
Monisha C Gowda
Muskan Gupta
Monisha R
Monisha CN
Mukta
SAPTHAGIRI NPS UNIVRSITY
2. QUEUE
• A Queue Data Structure is a fundamental concept in computer
science used for storing and managing data in a specific order.
• It follows the principle of "First in, First out" (FIFO), where the
first element added to the queue is the first one to be removed.
• Basic Terminologies of Queue:
1. Front: Position of the entry in a queue ready to be served,
that is, the first entry that will be removed from the queue, is
called the front of the queue. It is also referred as the head of
the queue.
2. Rear: Position of the last entry in the queue, that is, the one
most recently added, is called the rear of the queue. It is also
referred as the tail of the queue.
3. Size: Size refers to the current number of elements in the
queue.
4. Capacity: refers to the maximum number of elements the
4. OPERATIONS ON QUEUE
1. Enqueue: Enqueue operation adds (or stores) an element
to the end of the queue. Steps:
➢ Check if the queue is full. If so, return an overflow error and
exit.
➢ If the queue is not full, increment the rear pointer to the next
available position.
➢ Insert the element at the rear.
2. Dequeue: Dequeue operation removes the element at the
front of the queue. The following steps are taken to perform the
dequeue operation:
➢ Check if the queue is empty. If so, return an underflow error.
➢ Remove the element at the front.
➢ Increment the front pointer to the next element.
5. TYPES OF QUEUE
Queue data structure can be classified into 4
types:
1.Simple queue
2.Double-Ended queue(Deque)
3.Circular Queue
4.Priority Queue
6. SIMPLE QUEUE
• Simple Queue simply follows FIFO
Structure. We can only insert the element at
the back and remove the element from the
front of the queue.
7. 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. The Deque data structure supports clockwise and anticlockwise rotations in O(1)
time which can be useful in certain applications. Also, the problems where elements
need to be removed and or added both ends can be efficiently solved using Deque.
There are two types:
I. Input Restricted Queue: This is a simple queue. In this type of queue, the
input can be taken from only one end but deletion can be done from any of the ends.
II. Output Restricted Queue: This is also a simple queue. In this type of
queue, the input can be taken from both ends but deletion can be done from only one
end.
8. 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’. This
queue is primarily used in the following cases:
I. Memory Management: The unused memory
locations in the case of ordinary queues can be utilized in
circular queues.
II. Traffic system: In a computer-controlled traffic
system, circular queues are used to switch on the traffic
lights one by one repeatedly as per the time set.
III. CPU Scheduling: Operating systems often
maintain a queue of processes that are ready to execute or
that are waiting for a particular event to occur.
10. 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:
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.
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. The time complexity of the Priority Queue is
O(log n)
11. Applications of Queue Data Structure
•Linear Queue: A linear queue is a type of queue where data
elements are added to the end of the queue and removed from the
front of the queue. Linear queues are used in applications where data
elements need to be processed in the order in which they are
received. Examples include printer queues and message queues.
•Circular Queue: A circular queue is similar to a linear queue, but
the end of the queue is connected to the front of the queue. This
allows for efficient use of space in memory and can improve
performance. Circular queues are used in applications where the data
elements need to be processed in a circular fashion. Examples include
CPU scheduling and memory management.
12. •Priority Queue: A priority queue is a type of queue where each
element is assigned a priority level. Elements with higher priority
levels are processed before elements with lower priority levels.
Priority queues are used in applications where certain tasks or data
elements need to be processed with higher priority. Examples include
operating system task scheduling and network packet scheduling.
•Double-ended Queue: A double-ended queue, also known as
a deque, is a type of queue where elements can be added or removed
from either end of the queue. This allows for more flexibility in data
processing and can be used in applications where elements need to
be processed in multiple directions. Examples include job scheduling
and searching algorithms.
•Concurrent Queue: A concurrent queue is a type of queue that
is designed to handle multiple threads accessing the queue
simultaneously. Concurrent queues are used in multi-threaded
applications where data needs to be shared between threads in a
thread-safe manner. Examples include database transactions and web
server requests.
13. Real-time application of Queue:
1.Working as a buffer between a slow and
a fast device. For example keyboard and CPU,
and two devices on network.
2. ATM Booth Line
3. Ticket Counter Line
4. CPU task scheduling
5. Waiting time of each customer at call
centers.
14. Advantages of Queue
1) A large amount of data can be managed efficiently with
ease.
2) Operations such as insertion and deletion can be
performed with ease as it follows the first in first out rule.
3) Queues are useful when a particular service is used by
multiple consumers.
4) Queues are fast in speed for data inter-process
communication.
5) Queues can be used in the implementation of other
data structures.
15. Disadvantages of Queue
1) The operations such as insertion and deletion
of elements from the middle are time consuming.
2) In a classical queue, a new element can only
be inserted when the existing elements are
deleted from the queue.
3) Searching an element takes O(N) time.
4) Maximum size of a queue must be defined
prior in case of array implementation.
16. Issues of Queue
I. Queue overflow: Queue overflow occurs when the queue reaches its
maximum capacity and is unable to accept any more elements. This can cause data
loss and can lead to application crashes.
II. Queue underflow: Queue underflow occurs when an attempt is made to
remove an element from an empty queue. This can cause errors and application
crashes.
III. Priority inversion: Priority inversion occurs in priority queues when a
low-priority task holds a resource that a high-priority task needs. This can cause
delays in processing and can impact system performance.
IV. Deadlocks: Deadlocks occur when multiple threads or processes are waiting
for each other to release resources, resulting in a situation where none of the
threads can proceed. This can happen when using concurrent queues and can lead
to system crashes.
V. Performance issues: Queue performance can be impacted by various
factors, such as the size of the queue, the frequency of access, and the type of
operations performed on the queue. Poor queue performance can lead to slower
system performance and reduced user experience.
17. Case Study: Queue Implementation
in Customer Service System
ISSUE : A telecom company receives hundreds of
customer service requests every hour. These requests
must be processed in the order they are received to
ensure fairness. The company needed a system that
could handle this task efficiently.
SOLUTION : The development team implemented a
Queue data structure in their customer service software.
The First In, First Out (FIFO) property of queues was
ideal for managing incoming service requests.
18. IMPLEMENTATION DETAILS :
1.Data Structure Used:- Linear Queue using a circular array.
2.Operations Implemented :
(a)Enqueue() to add new service requests at the rear.
(b)Dequeue() to process the request at the front.
(c)isFull() and isEmpty() checks to manage queue capacity.
BENEFITS :
1.Maintained a strict order of service requests.
2.Reduced customer complaints due to fair processing.
3.Improved response time as queue management became
automated.
19. CONCLUSION
Using a queue ensured that the first
customer to raise a request was the first to
be served, leading to a transparent and
efficient customer service system.