Queue Notes
Queue Notes
A queue is a linear collection of elements .It is a data structure in which whatever comes first
will go out first. It follows the FIFO (First-In-First-Out) policy. In Queue, the insertion is done
from one end known as the rear end or the tail of the queue, whereas the deletion is done from
another end known as the front end or the head of the queue.
The condition to insert an element when there is no space is called as gives an overflow
condition
The condition to delete an element when there is no space is called as gives an underflow
condition
Circular queue
In the Circular Queue, all the nodes are represented as circular. It is similar to the linear Queue
except that the last element of the queue is connected to the first element. It is also known as
Ring Buffer as all the ends are connected to another end. The circular queue can be represented
as:
In a double ended queue, insertion and removal of elements can be performed from either from
the front or rear. Thus, it does not follow the FIFO (First In First Out) rule.z
There are two types of Queues, Input-restricted queue, and output-restricted queue.
1. Input-restricted queue: The input-restricted queue means that some restrictions are
applied to the insertion. In input-restricted queue, the insertion is applied to one end while
the deletion is applied from both the ends.
2. Output-restricted queue: The output-restricted queue means that some restrictions are
applied to the deletion operation. In an output-restricted queue, the deletion can be
applied only from one end, whereas the insertion is possible from both ends.
Priority queue
In a priority queue each element has some priority.The element with the highest priority would
come first in a priority queue. The priority of the elements in a priority queue will determine the
order in which elements are removed from the priority queue.
Following rules are applied to process the elements:
● An element with the higher priority will be deleted before the deletion of the lesser
priority.
● If two elements in a priority queue have the same priority, they will be arranged using the
FIFO principle.
Priority queues can be represented using following ways:
1. Priority queues using linklist
Each node is divided into 3 parts
The insertion takes place according to the priority of the queue while deletion takes place from
the front of link list
2. priority queues using multiple queues
It uses arrays as queues. In this a separate queue is maintained for all the elements with the same
priority which follows first in first out.They can also be used as circular queues. Each queue will
have a seperate front and rear.
To maintain such queues maximum no of elements with same priority and number of priority
levels have to be known in advance.