Question

Suppose a circular queue of capacity (n−1n - 1) elements is implemented with an array of nn elements. Assume that the insertion and deletion operations are carried out using REAR and FRONT as array index variables, respectively. Initially, REAR=FRONT=0\text{REAR} = \text{FRONT} = 0. The conditions to detect queue full and queue empty are

Choose one option
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.

  1. In an array of size nn, capacity is restricted to n−1n - 1 elements to unambiguously distinguish between queue empty and queue full conditions.

  2. Initially, both indices point to the same index:

Empty condition: REAR==FRONT\text{Empty condition: } \text{REAR} == \text{FRONT}
  1. As elements are enqueued, REAR is incremented circularly using modular arithmetic: (REAR+1) mod n(\text{REAR} + 1) \bmod n.

  2. When n−1n - 1 elements are stored in the queue, advancing REAR by one more step would cause it to reach FRONT. Thus, the queue full condition is detected when advancing REAR matches FRONT:

Full condition: (REAR+1) mod n==FRONT\text{Full condition: } (\text{REAR} + 1) \bmod n == \text{FRONT}
  1. This confirms option (A).
Final answer

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.