0% found this document useful (0 votes)
9 views4 pages

Understanding Queue Data Structure

A queue is a linear data structure that operates on a First In First Out (FIFO) basis, where additions occur at one end and deletions at the other. The front of the queue is where the first element is removed, while the rear is where the most recent element is added. The document also discusses algorithms for inserting and deleting elements in a queue, as well as the advantages of circular queues over normal queues.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Understanding Queue Data Structure

A queue is a linear data structure that operates on a First In First Out (FIFO) basis, where additions occur at one end and deletions at the other. The front of the queue is where the first element is removed, while the rear is where the most recent element is added. The document also discusses algorithms for inserting and deleting elements in a queue, as well as the advantages of circular queues over normal queues.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

QUEUE

Queue
A queue is a linear data structure that is open at both ends and the operations are performed in First
In First Out (FIFO) order.

We define a queue to be a list in which all additions to the list are made at one end, and all deletions
from the list are made at the other end. The element which is first pushed into the order, the delete
operation is first performed on that.

FIFO Principle of Queue:

1. A Queue is like a line waiting to purchase tickets, where the first person in line is the first
person served. (i.e. First come first serve).
2. 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(sometimes, head of the queue), similarly, the
position of the last entry in the queue, that is, the one most recently added, is called the rear
(or the tail) of the queue. See the below figure.
Array Representation of Queue
We can easily represent queue by using linear arrays. There are two variables i.e. front and rear, that
are implemented in the case of every queue. Front and rear variables point to the position from where
insertions and deletions are performed in a queue. Initially, the value of front and queue is -1 which
represents an empty queue. Array representation of a queue containing 5 elements along with the
respective values of front and rear, is shown in the following figure.

Algorithm to insert any element in a queue


Step 1: IF REAR = MAX - 1
Write OVERFLOW
Go to step
[END OF IF]

Step 2: IF FRONT = -1 and REAR = -1


SET FRONT = REAR = 0
ELSE
SET REAR = REAR + 1
[END OF IF]

Step 3: Set QUEUE[REAR] = NUM

Step 4: EXIT
Function to Insert element in an queue

Algorithm to delete an element from the queue


If, the value of front is -1 or value of front is greater than rear , write an underflow message and exit.

Otherwise, keep increasing the value of front and return the item stored at the front end of the queue
at each time.

Function to insert an element in an queue


Why circular queue is better than normal queue?

Suppose a queue is implemented by array. Write the algorithm to insert a new element at the kth
position of the array.

What is dequeue?

Write a short note on priority queue

You might also like