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. 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

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

Leaving one slot empty: the queue is empty when REAR == FRONT and full when (REAR + 1) mod n == FRONT.

More Data Structures and Algorithms questions