Question
Suppose a circular queue of capacity () elements is implemented with an array of elements. Assume that the insertion and deletion operations are carried out using REAR and FRONT as array index variables, respectively. Initially, . The conditions to detect queue full and queue empty are
Official answer and solution
- Official answer
- A
- From
- Official GATE 2012 answer key
Solution
Evaluate queue full and empty conditions in an array-based circular queue with one slot left unused.
-
In an array of size , capacity is restricted to elements to unambiguously distinguish between queue empty and queue full conditions.
-
Initially, both indices point to the same index:
-
As elements are enqueued,
REARis incremented circularly using modular arithmetic: . -
When elements are stored in the queue, advancing
REARby one more step would cause it to reachFRONT. Thus, the queue full condition is detected when advancingREARmatchesFRONT:
- This confirms option (A).
A
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2012 Computer Science and Information Technology (CS)
- Question
- 35 of 65, printed as CS Q.35
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.