Grokking the Engineering Manager Coding Interview
Vote

0% completed

Diving Deeper – Circular Queues and Deques

You now know how a simple queue works. This lesson covers the two variations that come up most often in interviews: the circular queue and the deque, which is short for double ended queue. A circular queue reuses the space that a simple queue wastes. A deque lets you add and remove at both ends.

Understanding Circular Queues

The Concept of a Circular Queue

In a Circular Queue, the last element points back to the first element making a circular link. We can visualize it as a circle where we remove elements from one end and add elements at the other end, and it goes on in a cycle.

.....

.....

.....

Like the course? Get enrolled and start learning!
E

ethanedge

· 2 months ago

This is not a deep dive on Deques, the title should really be updated.

Show 1 reply
V

Viktor

· 5 months ago

I believe this condition

} else if (rear == size - 1 && front != 0) { rear = 0; queue[rear] = element; }

is covered by the queue emptiness check:

if (front == (rear + 1) % size) { cout << "Queue is Full" << endl; }

so, the overall conditional can be simplified

Show 1 reply
T

tapasya234

· 7 months ago

The title suggests a deep dive into Circular Queues and Deques but it doesn't actually talk much about Deques. It has great content about Circular Queues and pitfalls about most queues in general but nothing about Deques.

Show 1 reply
Engin Yildirim

Engin Yildirim

· 2 years ago

We can do the following to check whether the queue is full or not when it is not empty:

if ((front == (rear + 1) % size)) { System.out.println("Queue is Full"); }

This condition unambiguously handles the wrap-around behaviour of the circular queue and ensures accurate detection of the full condition in all scenarios.

Show 1 reply
Leopoldo Hernandez

Leopoldo Hernandez

· 3 years ago

We really need more examples of circular queues and dequeues.

Especially with these data structures being implemented using linked lists rather than arrays.

Reading Progress

0%


Vote for new content