Data Structure
and Algorithm
By Group D:
Dipayan Sil (30183422022)
Priyanshu Mukherjee (30183422021)
Srijan Pradhan (30183422020)
Akash Hazra (30183422019)
Satyajit Dhar (30183422018)
:-Topic:-
Queues
Introduction on Queue
Queue is a linear data structure that follows
FIFO (First In First Out) Principle.
FIFO Principle states that the first element
added to the Queue will be the first one to
be removed or processed. So, Queue is like a
line of people waiting to purchase tickets,
where the first person in line is the first
person served.
Basic Terminologies of Queue
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.
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.
Size: Size refers to the current number of elements in the queue.
Capacity: Capacity refers to the maximum number of elements the queue can hold.
Basic operations on Queue
Some of the basic operations for Queue in Data Structure are:
enqueue() – Insertion of elements to the queue.
dequeue() – Removal of elements from the queue.
peek() or front()- Acquires the data element available at the front node of the queue without deleting it.
rear() – This operation returns the element at the rear end without removing it.
isFull() – Validates if the queue is full.
isEmpty() – Checks if the queue is empty.
size(): This operation returns the size of the queue i.e. the total number of elements it contains.
Implementation of Queue
Using Arrays (Static Implementation):-
The queue uses an array with a fixed capacity, referred to as
capacity, and tracks the current number of elements with a
variable size.
The variable front is initialized to 0 and represents the index
of the first element in the array. In the dequeue operation,
the element at this index is removed.
Using Linked List (Dynamic Implementation):-
A queue is generally implemented using an array, but the limitation of
this kind of queue is that the memory occupied by the array is fixed
no matter how many elements are in the queue. In the queue
implemented using a linked list, the size occupied by the linked list
will be equal to the number of elements in the queue. Moreover, its
size is dynamic, meaning that the size will change automatically
according to the elements present.
Circular Queue
A Circular Queue is another way of implementing a normal queue where the last element of the queue is
connected to the first element of the queue forming a circle.
Operations on Circular Queue:-
getFront: Get the front item from the queue.
getRear: Get the last item from the queue.
enqueue(value): To insert an element into the circular queue. In a circular queue, the new element is always
inserted at the rear position.
dequeue(): To delete an element from the circular queue. In a circular queue, the element is always deleted
from the front position.
Priority Queue
A priority queue is a special type of queue in which each element is associated with a priority value.
And, elements are served on the basis of their priority. That is, higher priority elements are served
first.
However, if elements with the same priority occur, they are served according to their order in the
queue.
Operations of a Priority Queue:
A typical priority queue supports the following operations:
• 1) Insertion : If the newly inserted item is of the highest priority, then it is inserted at the top. Otherwise, it is
inserted in such a way that it is accessible after all higher priority items are accessed.
• 2) Deletion in a Priority Queue : We typically remove the highest priority item which is typically available
at the top. Once we remove this item, we need mot move next priority item at the top.
• 3) Peek in a Priority Queue : This operation only returns the highest priority item (which is typically
available at the top) and does not make any change to the priority queue.
Deque (Double-Ended Queue)
Deque (Double-Ended Queue) is a generalized version of Queue data structure that allows insert and
delete at both ends. Operations on Deque are as follows:-
Operation Description Time Complexity
push_front() Inserts the element at the beginning. O(1)
push_back() Adds element at the end. O(1)
pop_front() Removes the first element from the deque. O(1)
pop_back() Removes the last element from the deque. O(1)
front() Gets the front element from the deque. O(1)
back() Gets the last element from the deque. O(1)
empty() Checks whether the deque is empty or not. O(1)
size()
Determines the number of elements in the
deque.
O(1)
Applications of Queues
1) CPU scheduling is a process used by the operating system to decide which task or process gets to use the
CPU at a particular time. This is important because a CPU can only handle one task at a time, but there are
usually many tasks that need to be processed.
2) Disk scheduling algorithms are crucial in managing how data is read from and written to a computer’s hard
disk. These algorithms help determine the order in which disk read and write requests are processed,
significantly impacting the speed and efficiency of data access. Common disk scheduling methods include
First-Come, First-Served (FCFS), Shortest Seek Time First (SSTF), SCAN, C-SCAN, LOOK, and C-LOOK.
3) Graph traversal refers to the process of visiting all the nodes in a graph systematically. Traversing a graph
is crucial in many real-world applications, as it enables efficient searching, data retrieval, and graph-based
decision-making. Two of the most commonly used techniques for graph traversal are Breadth-First Search
(BFS) and Depth-First Search (DFS).
Conclusion
In conclusion, queues are a fundamental data structure in computer science, widely
used in various applications such as scheduling, buffering, and real-time processing.
They operate on the FIFO (First In, First Out) principle, ensuring orderly execution
of tasks. Different types of queues, including simple queues, circular queues, priority
queues, and double-ended queues (deque), offer flexibility in managing data
efficiently.
Understanding queues is essential for optimizing algorithms and improving system
performance, particularly in areas like operating systems, networking, and database
management. Mastering queue operations and their implementations helps in
designing efficient and scalable software solutions.

Basic Terminologies of Queue...Basic operations on Queue

  • 1.
    Data Structure and Algorithm ByGroup D: Dipayan Sil (30183422022) Priyanshu Mukherjee (30183422021) Srijan Pradhan (30183422020) Akash Hazra (30183422019) Satyajit Dhar (30183422018) :-Topic:- Queues
  • 2.
    Introduction on Queue Queueis a linear data structure that follows FIFO (First In First Out) Principle. FIFO Principle states that the first element added to the Queue will be the first one to be removed or processed. So, Queue is like a line of people waiting to purchase tickets, where the first person in line is the first person served.
  • 3.
    Basic Terminologies ofQueue 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. 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. Size: Size refers to the current number of elements in the queue. Capacity: Capacity refers to the maximum number of elements the queue can hold.
  • 4.
    Basic operations onQueue Some of the basic operations for Queue in Data Structure are: enqueue() – Insertion of elements to the queue. dequeue() – Removal of elements from the queue. peek() or front()- Acquires the data element available at the front node of the queue without deleting it. rear() – This operation returns the element at the rear end without removing it. isFull() – Validates if the queue is full. isEmpty() – Checks if the queue is empty. size(): This operation returns the size of the queue i.e. the total number of elements it contains.
  • 5.
    Implementation of Queue UsingArrays (Static Implementation):- The queue uses an array with a fixed capacity, referred to as capacity, and tracks the current number of elements with a variable size. The variable front is initialized to 0 and represents the index of the first element in the array. In the dequeue operation, the element at this index is removed. Using Linked List (Dynamic Implementation):- A queue is generally implemented using an array, but the limitation of this kind of queue is that the memory occupied by the array is fixed no matter how many elements are in the queue. In the queue implemented using a linked list, the size occupied by the linked list will be equal to the number of elements in the queue. Moreover, its size is dynamic, meaning that the size will change automatically according to the elements present.
  • 6.
    Circular Queue A CircularQueue is another way of implementing a normal queue where the last element of the queue is connected to the first element of the queue forming a circle. Operations on Circular Queue:- getFront: Get the front item from the queue. getRear: Get the last item from the queue. enqueue(value): To insert an element into the circular queue. In a circular queue, the new element is always inserted at the rear position. dequeue(): To delete an element from the circular queue. In a circular queue, the element is always deleted from the front position.
  • 7.
    Priority Queue A priorityqueue is a special type of queue in which each element is associated with a priority value. And, elements are served on the basis of their priority. That is, higher priority elements are served first. However, if elements with the same priority occur, they are served according to their order in the queue. Operations of a Priority Queue: A typical priority queue supports the following operations: • 1) Insertion : If the newly inserted item is of the highest priority, then it is inserted at the top. Otherwise, it is inserted in such a way that it is accessible after all higher priority items are accessed. • 2) Deletion in a Priority Queue : We typically remove the highest priority item which is typically available at the top. Once we remove this item, we need mot move next priority item at the top. • 3) Peek in a Priority Queue : This operation only returns the highest priority item (which is typically available at the top) and does not make any change to the priority queue.
  • 8.
    Deque (Double-Ended Queue) Deque(Double-Ended Queue) is a generalized version of Queue data structure that allows insert and delete at both ends. Operations on Deque are as follows:- Operation Description Time Complexity push_front() Inserts the element at the beginning. O(1) push_back() Adds element at the end. O(1) pop_front() Removes the first element from the deque. O(1) pop_back() Removes the last element from the deque. O(1) front() Gets the front element from the deque. O(1) back() Gets the last element from the deque. O(1) empty() Checks whether the deque is empty or not. O(1) size() Determines the number of elements in the deque. O(1)
  • 9.
    Applications of Queues 1)CPU scheduling is a process used by the operating system to decide which task or process gets to use the CPU at a particular time. This is important because a CPU can only handle one task at a time, but there are usually many tasks that need to be processed. 2) Disk scheduling algorithms are crucial in managing how data is read from and written to a computer’s hard disk. These algorithms help determine the order in which disk read and write requests are processed, significantly impacting the speed and efficiency of data access. Common disk scheduling methods include First-Come, First-Served (FCFS), Shortest Seek Time First (SSTF), SCAN, C-SCAN, LOOK, and C-LOOK. 3) Graph traversal refers to the process of visiting all the nodes in a graph systematically. Traversing a graph is crucial in many real-world applications, as it enables efficient searching, data retrieval, and graph-based decision-making. Two of the most commonly used techniques for graph traversal are Breadth-First Search (BFS) and Depth-First Search (DFS).
  • 10.
    Conclusion In conclusion, queuesare a fundamental data structure in computer science, widely used in various applications such as scheduling, buffering, and real-time processing. They operate on the FIFO (First In, First Out) principle, ensuring orderly execution of tasks. Different types of queues, including simple queues, circular queues, priority queues, and double-ended queues (deque), offer flexibility in managing data efficiently. Understanding queues is essential for optimizing algorithms and improving system performance, particularly in areas like operating systems, networking, and database management. Mastering queue operations and their implementations helps in designing efficient and scalable software solutions.