Queue in Data Structure
What is a Queue?
A queue is a sequential data structure that follows the FIFO (First in Last Out) approach.
A queue can be defined as an ordered list which enables insert operations to be performed at one end called Rear end delete operations to be performed at another end called Front.
For example:- people waiting in line for a rail ticket from a queue.
Representation of Queue in Memory:-
1. Static Implementation (Using Array):-
Static implementation of Queue is represented by arrays. If Queue is implemented using arrays, we must be sure about the exact number of elements we want to store in the queue, because we have to declare the size of the array at design time or before the processing starts.
2. Dynamic implementation (Using Linked list):-
In a linked queue, each node of the queue consists of two parts i.e. data part and the link part. Each element of the queue points to its immediate next element in the memory.
In the linked queue, there are two pointers maintained in the memory i.e. front pointer and rear pointer. The front pointer contains the address of the starting element of the queue while the rear pointer contains the address of the last element of the queue.
1. Linear Queue:-
• It is a linear data structure.
• It is considered as sequence of items. It is a linear data structure. It is considered as sequence of items. FIFO (First In First Out) property.
• It supports FIFO (First In First Out)
• It has three components:
- A Container of items o A pointer front that points the first item of the queue.
- A pointer rear that points the last item of the queue.
- Container of items that contains elements of queue. that points the first item of the queue.
2. Circular Queue:-
• It is a linear data structure in which the last position is connected back to the first position to make a circle.
• It follows FIFO (First In First Out) principle.
• It overcomes the limitation of linear queue such as memory wastage.
• In circular queue, when the rear reaches the last position, it starts again from the beginning (if space is available).
• It has two pointers:
- Front → points to the first element
- Rear → points to the last element
• Insertion is performed from REAR end.
• Deletion is performed from FRONT end.
• Insertion operation is also known as ENQUEUE.
• Deletion operation is also known as DEQUEUE.
Advantages of Circular Queue:-
• Efficient use of memory
• No false overflow condition
Structure of Circular Queue:-
3. Priority Queue:-
• It is a special type of queue in which each element is associated with a priority.
• Elements are processed based on priority instead of FIFO.
• The element with highest priority is removed first.
• If two elements have the same priority, then they are served according to FIFO.
• It can be implemented using arrays, linked list or heap.
Types of Priority Queue:-
• Ascending Priority Queue (Lower value = higher priority)
• Descending Priority Queue (Higher value = higher priority)
Applications of Priority Queue:-
• CPU scheduling
• Dijkstra’s shortest path algorithm
Structure of Priority Queue:-
4. Deque (Double Ended Queue):-
• Deque stands for Double Ended Queue.
• It is a type of queue in which insertion and deletion can be performed from both ends (front and rear).
• It does not strictly follow FIFO.
Types of Deque:-
-
Input Restricted Deque:-
• Insertion is allowed at only one end (usually rear).
• Deletion is allowed at both ends. -
Output Restricted Deque:-
• Insertion is allowed at both ends.
• Deletion is allowed at only one end (usually front).
Applications of Deque:-
• Sliding window problems
• Palindrome checking
Structure of Deque:-









0 Comments