Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email
Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

# Difference between Linear Queue and Circular Queue

Last Updated on April 25, 2023 by Prepbytes

In the field of programming, a queue is defined as an abstract data type that is used to store and manage a collection of elements in a particular order (FIFO, to be precise). A linear queue and a circular queue are two common implementations of this data structure. Although they both serve the same purpose, there are some notable differences between the two. Here, we are going to discuss the difference between queue and circular queue. But before jumping directly into the difference between linear queue and circular queue, let us first learn about linear queue and circular queue in brief.

### Linear Queue

Linear Queue is a linear data structure that works on the principle of First-In-First-Out (FIFO) which means that the element which is added first will be the first one to be removed. There is one criterion i.e. element is always added in the rear part or the end part of the queue and always deleted from the front part of the queue. The enqueue operation takes place on the rear end whereas the dequeue operation takes place on the front end. Insertion of elements from the rear end in the queue is known as enqueue operation and deletion of elements from the front end of the queue is known as dequeue operation. The below image shows the pictorial representation of a linear queue.

### Circular Queue

A circular queue, on the other hand, is an improvement over the linear queue that addresses the problem of overflow. It is also a linear data structure that works on the principle of FIFO (First in First out). In this type of queue, the element can be added in any position or can be deleted from any position in the array but we have to maintain the pointers which will point towards the front and rear end of the queue. When an element is added to the rear end of the circular queue, the rear pointer is incremented. When an element is removed from the front end of the circular queue, the front pointer is incremented.

### Difference between Linear Queue and Circular Queue

The table given below shows the difference between queue and circular queue.

S. no. Linear Queue Circular Queue
1. In this type of queue, elements are arranged in the linear pattern. In this type of queue, elements are arranged in the circular pattern where the rear end is connected with the front end.
2. In this queue, the insertion and deletion are fixed i.e. done at the rear and front end respectively. In this queue, insertion and deletion can be done from any position. They are not fixed.
3. Linear queue requires more memory. In comparison to a linear queue, the circular queue requires less memory.
4. A linear queue is inefficient when compared to a circular queue. It is more efficient in comparison to a linear queue.
5. In this type of queue, peek value can be fetched very easily. In this type of queue, fetching the peak value is not an easy job.
6. In a linear queue, if there are 20 spaces, then in best case all the 20 spaces can be filled. In a circular queue, if there are 20 spaces, then in best case 19 spaces can be filled at a time.
7. Linear queues are used to represent the cars waiting in line on a bridge or people standing in a queue at a bank counter or a bus stop. Circular queues are used for CPU scheduling and memory management.
8. In this case, the element added in the first position is going to be deleted in the first position. The order of operations performed on any element is fixed i.e. FIFO. In this case, the order of operation performed on an element may change.

Conclusion
In conclusion, both linear queue and circular queue are data structures that are used to manage a collection of elements in a particular order. The main difference between linear queue and circular queue is that a linear queue has a fixed size and can overflow, while a circular queue is circular and has no overflow limitation. Choosing between the two depends on the specific requirements of the application.

Here are some frequently asked questions on the difference between linear queue and circular queue.

Ques 1. What is overflow in a queue?
Ans. Overflow occurs when a queue is full and can no longer accept any new elements.

Ques 2. How do you check if a linear queue is empty?
Ans. To check if a linear queue is empty, you check if the front pointer is equal to the rear pointer.

Ques 3. How do you check if a circular queue is full?
Ans. To check if a circular queue is full, you check if the next position of the rear pointer is equal to the front pointer.

Ques 4. What happens when a linear queue is full?
Ans. When a linear queue is full, it can no longer accept any new elements, and it overflows.