Skip to content
Official PYQ · 2012

GATE CS 2012 Q35 — Arrays, Stacks and Queues

Explain with AI

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

Choose one option
View worked solution

Answer: A

To understand the conditions for a circular queue of capacity n−1n-1 implemented using an array of size nn, let us trace the operations with a small example.

1. Queue Empty Condition

Initially, the queue is empty, and we are given that:

REAR=FRONT=0\text{REAR} = \text{FRONT} = 0

Since this is the starting state where no elements are present, the condition to detect an empty queue is:

REAR==FRONT\text{REAR} == \text{FRONT}

2. Queue Full Condition

Let the array size be n=4n = 4. The capacity of the queue is n−1=3n - 1 = 3 elements.

  • Initial State: FRONT=0,REAR=0\text{FRONT} = 0, \text{REAR} = 0 (Queue is empty).
  • Insert 1st element: Stored at index 00. REAR\text{REAR} is updated to (0+1) mod 4=1(0 + 1) \bmod 4 = 1.
  • Insert 2nd element: Stored at index 11. REAR\text{REAR} is updated to (1+1) mod 4=2(1 + 1) \bmod 4 = 2.
  • Insert 3rd element: Stored at index 22. REAR\text{REAR} is updated to (2+1) mod 4=3(2 + 1) \bmod 4 = 3.

At this point, the queue has reached its maximum capacity of 33 elements. The array index 33 is left unused to distinguish the "full" state from the "empty" state.

If we try to insert another element, the next position for REAR\text{REAR} would be:

(REAR+1) mod n=(3+1) mod 4=0(\text{REAR} + 1) \bmod n = (3 + 1) \bmod 4 = 0

Since this value matches FRONT\text{FRONT} (which is 00), the queue is full. Thus, the condition for a full queue is:

(REAR+1) mod n==FRONT(\text{REAR} + 1) \bmod n == \text{FRONT}

Conclusion

  • full\text{full}: (REAR+1) mod n==FRONT(\text{REAR} + 1) \bmod n == \text{FRONT}
  • empty\text{empty}: REAR==FRONT\text{REAR} == \text{FRONT}

This corresponds to Option A.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Arrays, Stacks and Queues questions