In a circular queue of size 5, if the front pointer is at index 3 and the rear pointer is at index 1, how many elements are currently in the queue?
Remember that in a circular queue, the rear can wrap around to the start of the array.
The number of elements is calculated as (rear - front + size) % size. Here, (1 - 3 + 5) % 5 = 3.
Which of the following is a key advantage of using a circular queue over a simple linear queue?
Think about what happens when elements are removed from the front in a linear queue.
A circular queue reuses the spaces freed by dequeued elements, preventing wasted space that occurs in a linear queue.
In a circular queue of size 7, the rear pointer is currently at index 6. After inserting one element, what will be the new rear pointer index?
Remember that the rear pointer wraps around to the start when it reaches the end.
Since the queue size is 7, the rear pointer moves to (6 + 1) % 7 = 0 after insertion.
Which condition correctly indicates that a circular queue is full?
Think about how the pointers relate when the queue has no free space left.
The queue is full when the next position of rear equals front, meaning no space to insert new elements.
When implementing a circular queue using an array, why is it important to leave one slot empty?
Consider how front and rear pointers behave when the queue is empty versus full.
Leaving one slot empty helps differentiate full and empty states because if front == rear, the queue is empty; if rear is just before front, the queue is full.