Science, asked by sultananon755, 2 months ago

why should we use circular queue lnstead of a simple or double ended queue? explain​

Answers

Answered by sangeetasoreng98
1

In linear queue, insertion is done from the rear end, and deletion is done from the front end. In circular queue, the insertion and deletion can take place from any end. The memory space occupied by the linear queue is more than the circular queue. It requires less memory as compared to linear queue.

Answered by rajeshwari46
0

Explanation:

Circular Queue

In an Queue when elements are arranged in sequential manner but logically we assume it in circular format, then such queue is called as “Circular Queue”.

It follows “First In First Out” method for insertion and deletion of elements.

Liner Queue may appear to be full although there may be space in the queue, this problem is overcome due to circular nature of circular queue.

A variable named “FRONT” stores position of the starting element of the queue. Its incremented on deletion of an element.

A variable named “REAR” stores position of the last element of the queue. Its incremented on Insertion of new element.

Example

enter image description here

In the above example, if another element, G is added to the queue, i.e. rear and front coincide. 8.To check Queue is Full or Not following condition is used front == (rear+1)%SIZE, if the condition is true then the Queue is full or else not full.

To check Queue is Empty or Not following condition is used rear == front, if the condition is true then the Queue is Empty or else not empty

Double Ended Queue

A Queue in which inserting and deleting of elements is done from both the ends, such queue is called as Double Ended Queue(DeQueue).

Consider the following enter image description here

Dequeue always consists of homogeneous list of elements.

There are two types of DeQueue. A. Input restricted dequeues B. Output restricted dequeues

Following are the types of DEQueue enter image description here

Input restricted dequeues allows insertion only at one end but allows deletion of element from both the ends.

Output restricted dequeues allwos deletions of elements only at one end but allows insertion of element from both the ends.

Similar questions