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.
4676 Points
4004 Points
3738 Points
2966 Points
2278 Points
2212 Points
1814 Points
1788 Points
1444 Points
Gatecse