– A queue is implemented by a linear array of size 10 (and not as a circularly connected Array). Front and Rear are represented as an index in the array. To add an element, the rear index is incremented and the element is added. To delete an element, the front index is incremented. The following operations are done on an empty queue. ADD 1; DELETE; ADD 2; ADD 3; ADD 4; DELETE, DELETE After this set of operations, what is the maximum capacity of the queue?
A. 6
B. 7
C. 10
D. None of these
Answer:B
– A queue is implemented by a linear array of size 10 (and not as a circularly connected Array). Front and Rear are represented as an index in the array. To add an element, the rear index is incremented and the element is added. To delete an element, the front index is incremented. The following operations are done on an empty queue. ADD 1; DELETE; ADD 2; ADD 3; ADD 4; DELETE, DELETE After this set of operations, what is the maximum capacity of the queue?
A. 6 B. 7 C. 10 D. None of these
Explanation: In queue initially the both Front and Rear assigned by the value -1 means the queue is empty. The size of the queue is 10 (array index no from 0 to 9).ADD 1 it will increment both Front and Rear (in case of first element)DELETE deletion of element set the Front and Rear to -1(queue is empty)ADD 2 Front = 0 ,Rear = 0ADD 3 Front = 0 ,Rear = 1ADD 4 Front = 0 ,Rear = 2DELETE Front = 1 ,Rear = 2DELETE Front = 2 ,Rear = 2Now the empty location in the queue is 7 so the maximum capacity of queue is 7 . In spite 2 location is empty in left side of the last element 4 but queue cannot access these location as the front on the location 2 this is the disadvantage of simple to queue to overcome this problem circular queue is implemented.