Suppose a circular queue of capacity (n - 1) elements is implemented with an array of n...
Palo Alto Networks technical mcq question, verified with a worked answer. Free to practise - no sign-up.
Suppose a circular queue of capacity (n - 1) elements is implemented with an array of n elements. Assume that the insertion and deletion operation 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-
**Select any one of the following
Show answer & explanation
In a circular array of size n with capacity n-1, full condition leaves one empty slot ((REAR + 1) % n == FRONT), while empty is when REAR == FRONT.
Step-by-step Derivation:
Step 1: When FRONT == REAR, the circular queue contains no elements (empty).
Step 2: To distinguish full from empty without an extra counter, one slot is sacrificed.
Step 3: The queue is full when the next position of REAR coincides with FRONT: (REAR + 1) % n == FRONT.