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.
5128 Points
3054 Points
2920 Points
2732 Points
2602 Points
1574 Points
1422 Points
1386 Points
1350 Points
1128 Points
Gatecse