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 variables, respectively. Initially, REAR = FRONT = 0. The conditions to detect queue full and queue empty are (A)
full: (REAR+1) mod n == FRONT
empty: REAR == FRONT$
(B)
empty: (FRONT+1) mod n == REAR
(C)
full: REAR == FRONT
empty: (REAR+1) mod n == FRONT
(D)
full: (FRONT+1) mod n == REAR
empty: REAR == FRONT
rear = Write
front = Read
Only option A matches.
No. FRONT will be pointing to the first item in the queue, while REAR will be pointing to the next empty location.
See this :
D -> This is incorrect, because if you have two elements in Queue of size 5, Front + 1 will not point to Rear. full: (FRONT+1) mod n == REAR is incorrect.
C-> full: REAR == FRONT This is wrong part. Even initially we had rear = front = 0 , does this means queue is full ?
B-> empty: (FRONT+1) mod n == REAR , Initially queuee is empty, still this heuristic will say that queue is not empty. As Rear = front = 0, So Front + 1 % mod n = 1 != 0
A is correct option.
3338 Points
2108 Points
1922 Points
1682 Points
1614 Points
1272 Points
1208 Points
1056 Points
1018 Points
812 Points
1008 Points
734 Points
726 Points
342 Points
328 Points
Gatecse