1. Introduction

In this article, we’ll learn four types of queues with their applications. Let’s understand them one-by-one with an illustration.

2. Simple Queue

A simple queue is the most basic queue. In this queue, the enqueue operation takes place at the rear, while the dequeue operation takes place at the front:

simple queue 2

Its applications are process scheduling, disk scheduling, memory management, IO buffer, pipes, call center phone systems, and interrupt handling.

3. Circular Queue

A circular queue permits better memory utilization than a simple queue when the queue has a fixed size.

In this queue, the last node points to the first node and creates a circular connection. Thus, it allows us to insert an item at the first node of the queue when the last node is full and the first node is free.

It’s also called a ring buffer:

circular queue

It’s used to switch on and off the lights of the traffic signal systems. Apart from that, it can be also used in place of a simple queue in all the applications mentioned above.

4. Priority Queue

A priority queue is a special kind of queue in which each item has a predefined priority of service. In this queue, the enqueue operation takes place at the rear in the order of arrival of the items, while the dequeue operation takes place at the front based on the priority of the items.

That is to say that an item with a high priority will be dequeued before an item with a low priority.

In the case, when two or more items have the same priority, then they’ll be dequeued in the order of their arrival. Hence, it may or may not strictly follow the FIFO rule:

priority queue

It’s used in interrupt handling, Prim’s algorithm, Dijkstra’s algorithm,  A* search algorithm, heap sort, and Huffman code generation.

5. Double-Ended Queue (Deque)

A deque is also a special type of queue. In this queue, the enqueue and dequeue operations take place at both front and rear. That means, we can insert an item at both the ends and can remove an item from both the ends. Thus, it may or may not adhere to the FIFO order:

deque

It’s used to save browsing history, perform undo operations, implement A-Steal job scheduling algorithm, or implement a stack or implement a simple queue.

Further, it has two special cases: input-restricted deque and output-restricted deque.

In the first case, the enqueue operation takes place only at the rear, but the dequeue operation takes place at both rear and front:

input restricted deque

An input-restricted queue is useful when we need to remove an item from the rear of the queue.

In the second case, the enqueue operation takes place at both rear and front, but the dequeue operation takes place only at the front:

output restricted deque

An output-restricted queue is handy when we need to insert an item at the front of the queue.

6. Conclusion

In this article, we’ve learned four kinds of queues with their applications.

2 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.