All mock tests are FREE till 31 December — register to save your progress

Suppose a circular queue of capacity n − 1 elements is implemented with an array of n elements. Insertion and deletion use REAR and FRONT as array index variables respectively. Initially REAR = FRONT = 0. The conditions to detect queue empty and queue full are

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: A. EMPTY: REAR == FRONT; FULL: (REAR + 1) mod n == FRONT

Explanation

One slot is kept empty: the queue is empty when REAR == FRONT and full when advancing REAR would make it equal to FRONT.

More Data Structures and Algorithms questions