Q55.Marks: +2.0UGC NET Paper 2: Computer Science17th June 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.
EMPTY : REAR == FRONT
FULL : (REAR + 1) mod n == FRONT
✓ Correct
2.
EMPTY : (FRONT + 1) mod n == REAR
FULL : (REAR + 1) mod n == FRONT
3.
EMPTY (REAR + 1) mod n == FRONT
FULL : REAR == FRONT
4.
EMPTY : REAR == FRONT
FULL : (FRONT + 1) mod n == REAR
Solution
The Correct answer is EMPTY : REAR == FRONT and FULL : (REAR + 1) mod n == FRONT
Key Points A circular queue is a queue whose last position is connected back to the first position.
ENQUEUE – It is the operation to insert elements into the queue.
DEQUEUE – It is the operation to delete elements from the queue.
After inserting an element in the last position, the next element again gets inserted into the first position.
EXPLANATION:
Given, Rear = Front = 0
Here, the Rear is used to insert elements & the front is used to delete elements.
To check full condition in queue:
(Rear + 1) % n == Front
Example: Consider queue is full that means Rear = 6, front = 0, n = 7
(6+1) % 7 = 7 % 7 = 0
To check empty condition in queue:
Rear == Front
Example: Consider queue is empty that means Rear = 0, front = 0, n = 7