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.
@ Prashant. this figure is not compitable with ques.
you take the array index from 0 to n now there will be n+1 slots are available in array but in ques circular queue of capacity (n−1) elements is implemented with an array of n elements.
then how can u implement a circular queue of capacity (n−1) elements with an array of n+1elements.
initially rear=front=0 { means queue is empty}
if(rear=front=0) {
F++
R++}
1st element should be inserted at location 1
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.
8796 Points
3572 Points
2914 Points
2840 Points
2550 Points
2268 Points
1990 Points
1874 Points
1820 Points
1718 Points
Gatecse