In: Computer Science
1) Given an array queue implementation with one unused entry and frontIndex and backIndex references, match the status of the queue with the following information about frontIndex and backIndex for a queue with capacity of 5:
a.) frontIndex is 0 and backIndex is 4
b.) frontIndex is 1 and backIndex is 4
c.) frontIndex is 3 and backIndex is 0
empty queue
one element in the queue
three elements in the queue
four elements in the queue
five elements in the queue
six elements in the queue
invalid
Please Help!
a) four elements in the queue
As we know, we can only add an element in the back and remove an element from the front in the queue. So, according to this option, the back index is in 4th position means the user entered 4 elements in the queue i.e. in {0,1,2,3} positions and the front index is still in 0th index means the user didn't remove any element yet. The user still didn't use the 4th index. So, the queue contains 4 elements in it.
b) three elements in the queue
As we know, we can only add an element in the back and remove an element from the front in the queue. So, according to this option, the back index is in 4th position means the user entered 4 elements in the queue i.e. in {0,1,2,3} positions and the front index is in 1st index means the user removed 1 element from index 0. The user still didn't use the 4th index. So, the queue contains 3 elements in it.
c) Invalid
As we know, we can only add an element in the back and remove an element from the front in the queue. If it is a Circular Queue, then there is a possibility that the back index came before the front index but In Normal Queue, back index never came before front index. So, this option is Invalid.