Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Queue

A Queue is a FIFO data structure where insertions occur at the rear and deletions at the front. Key operations include enqueue, dequeue, isEmpty, and isFull, with specific algorithms for each. Various types of queues include double-ended, circular, and priority queues, and they are used in applications like simulation, batch processing, and scheduling algorithms.

Uploaded by

mishrakd22
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)
39 views4 pages

Queue

A Queue is a FIFO data structure where insertions occur at the rear and deletions at the front. Key operations include enqueue, dequeue, isEmpty, and isFull, with specific algorithms for each. Various types of queues include double-ended, circular, and priority queues, and they are used in applications like simulation, batch processing, and scheduling algorithms.

Uploaded by

mishrakd22
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
You are on page 1/ 4

Queue

1. Define Queue.

A Queue is an ordered list in which all insertions take place at one end called the rear, while all deletions
take place at the other end called the front. Rear is initialized to -1 and front is initialized to 0. Queue is
also referred as First In First Out (FIFO) list.

2. What are the various operations performed on the Queue? The

various operations performed on the queue are CREATE(Q) –

Creates Q as an empty Queue.

Enqueue(Q,X) – Adds the element X to the Queue. Dequeue(Q) –

Deletes a element from the Queue. ISEMTPTY(Q) – returns true if

Queue is empty else false. ISFULL(Q) - returns true if Queue is full

else false.

Queue Insertion Operation: Enqueue()

The enqueue() is a data manipulation operation that is used to insert elements into the stack. The following

algorithm describes the enqueue() operation in a simpler way.

Algorithm

1. START
2. Check if the queue is full.
3. If the queue is full, produce overflow error and exit.
4. If the queue is not full, increment rear pointer to point the next empty space.
5. Add data element to the queue location, where the rear is pointing.
6. return success.
7. END
Example

Queue Deletion Operation: dequeue()


The dequeue() is a data manipulation operation that is used to remove elements from the stack. The
following algorithm describes the dequeue() operation in a simpler way.
Algorithm
1. START
2. Check if the queue is empty.
3. If the queue is empty, produce underflow error and exit.
4. If the queue is not empty, access the data where front
is pointing.
5. Increment front pointer to point to the next available
data element.
6. Return success.
7. END

Queue - The isFull() Operation

The isFull() operation verifies whether the stack is full.


Algorithm
1. START
2. If the count of queue elements equals the queue size,
return true
3. Otherwise, return false
4. END

Queue - The isEmpty() operation

The isEmpty() operation verifies whether the stack is empty. This operation is used to check the status of
the stack with the help of top pointer.
Algorithm
1. START
2. If the count of queue elements equals zero, return true
3. Otherwise, return false
4. END

What are the applications of queue?

The following are the areas in which queues are applicable


a. Simulation
b. Batch processing in an operating systems
c. Multiprogramming platform systems
d. Queuing theory
e. Printer server routines
f. Scheduling algorithms like disk scheduling , CPU scheduling
g. I/O buffer requests

What are the types of queue?


The following are the types of queue:
● Double ended queue
● Circular queue
● Priority queue
Define double ended queue
It is a special type of queue that allows insertion and deletion of elements at both

Define Circular Queue.


Another representation of a queue, which prevents an excessive use of memory by arranging
elements/ nodes Q1,Q2,…Qn in a circular fashion. That is, it is the queue, which wraps around upon
reaching the end of the queue

Operations on Circular Queue


There are mainly four operations that can be performed on a circular queue:
 Enqueue: Insert an element into the circular queue.
 Dequeue: Delete an element from the circular queue.
 Front: Get the front element from the circular queue.
 Rear: Get the last element from the circular queue.
Algorithm for Enqueue Operation in Circular Queue
1.Initialize an array or any data structure to store the elements of the circular queue.
2.Initialize two variables front and rear.
3.Check if the circular queue is full.
4.If it is not full, and if the front is -1, set the front to 0.
5.Increment the rear by 1 and store it in the rear index.
6.Update the rear index using rear = (rear + 1) % SIZE.

Algorithm for Dequeue Operation in Circular Queue


1.Check if the circular queue is empty.
2.If the queue is not empty, store the element at the front index.
3.If the front and rear are equal, set the front and rear to -1.
4.Else, increase the front index by 1 using the formula front = (front + 1) % SIZE.
5.At last print the deleted element.

Distinguish between stack and queue.

STACK QUEUE

Insertion and deletion are made at one end. Insertion at one end rear and deletion at other
end front.

The element inserted last would be removed The element inserted first would be removed
first. So LIFO structure. first. So FIFO structure.

Full stack condition: If(top==Maxsize) Full stack condition: If(rear = = Maxsize)


Physically and Logically full stack Logically full. Physically may or may not be
full.

Q 1. A circular queue has a size of 5 and has 3 elements 10,20 and 40 where F=2 and R=4. After inserting
50 and 60, what is the value of F and R. Trying to insert 30 at this stage what happens? Delete 2 elements
from the queue and insert 70, 80 & 90. Show the sequence of steps with necessary diagrams with the value of
F & R.
All the operations of Queue is done with O(1) complexity

You might also like