Suppose a circular queue of capacity (n−1) elements is implemented with an…

2023

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 variable respectively. Initially, REAR = FRONT = 0. The conditions to detect queue empty and queue full are

  1. A.

    EMPTY: REAR == FRONT,

    FULL: (REAR + 1) mod n == FRONT

  2. B.

    EMPTY: (FRONT + 1) mod n == REAR

    FULL: (REAR + 1) mod n == FRONT

  3. C.

    EMPTY: (REAR + 1) mod n == FRONT

    FULL: REAR == FRONT

  4. D.

    EMPTY: REAR == FRONT

    FULL: (FRONT + 1) mod n == REAR

Attempted by 183 students.

Show answer & explanation

Correct answer: A

In a circular queue with array size n and capacity n-1, the empty condition occurs when FRONT equals REAR. The full condition is detected when (REAR + 1) mod n equals FRONT, ensuring one slot remains unused to differentiate between empty and full states.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Coding For Placement