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?
Answers
Answered by
11
7. Actually as the size of the array is 10, at most 10 Add and 10 delete can be done... Since 3 delete are done, 7 more locations remain.
Array : from Array[1] to Array[10]
empty Q. Front = 1 Rear = 0
Add 1 Rear = 1 "1" is in Array[1]
Delete Front = 2
Add 2 Rear = 2 "2" is in Array[2]
Add 3 Rear = 3 "3" in Array[3]
Add 4 Rear = 4 4 in Array[4]
Delete Front = 3
Delete Front = 4
At this point, There are 6 more elements can be added in the array. There is one element in the queue already. The maximum capacity of the queue is 7.
Array : from Array[1] to Array[10]
empty Q. Front = 1 Rear = 0
Add 1 Rear = 1 "1" is in Array[1]
Delete Front = 2
Add 2 Rear = 2 "2" is in Array[2]
Add 3 Rear = 3 "3" in Array[3]
Add 4 Rear = 4 4 in Array[4]
Delete Front = 3
Delete Front = 4
At this point, There are 6 more elements can be added in the array. There is one element in the queue already. The maximum capacity of the queue is 7.
Similar questions