StreakPeaked· Practice

ExamsGATETechnical

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

  1. full: $(\text{REAR} + 1) \bmod n = \text{FRONT}$; empty: REAR = FRONT
  2. full: $(\text{REAR} + 1) \bmod n = \text{FRONT}$; empty: $(\text{FRONT} + 1) \bmod n = \text{REAR}$
  3. full: REAR = FRONT; empty: $(\text{REAR} + 1) \bmod n = \text{FRONT}$
  4. full: $(\text{FRONT} + 1) \bmod n = \text{REAR}$; empty: REAR = FRONT

Correct answer: full: $(\text{REAR} + 1) \bmod n = \text{FRONT}$; empty: REAR = FRONT

Solution

In a circular queue of capacity $n-1$ using an array of size $n$, one slot is kept empty to distinguish full from empty. The queue is empty when FRONT and REAR are equal, and it is full when advancing REAR by one position would make it equal to FRONT.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →