chap listsstacksand queues front rear (afront rear (bfigure after repeated useelements in the array-based queue will drift to the back of the array (athe queue after the initial four numbers and have been inserted (bthe queue after elements and are deletedfollowing which and are inserted enqueue operations will require th(ntimebecause the elements currently in the queue must each be shifted one position in the array if instead we chose the rear element of the queue to be in position then an enqueue operation is equivalent to an append operation on list this requires only th( time but nowa dequeue operation requires th(ntimebecause all of the elements must be shifted down by one position to retain the property that the remaining queue elements reside in the first positions of the array far more efficient implementation can be obtained by relaxing the requirement that all elements of the queue must be in the first positions of the array we will still require that the queue be stored be in contiguous array positionsbut the contents of the queue will be permitted to drift within the arrayas illustrated by figure nowboth the enqueue and the dequeue operations can be performed in th( time because no other elements in the queue need be moved this implementation raises new problem assume that the front element of the queue is initially at position and that elements are added to successively higher-numbered positions in the array when elements are removed from the queuethe front index increases over timethe entire queue will drift toward the higher-numbered positions in the array once an element is inserted into the highest-numbered position in the arraythe queue has run out of space this happens despite the fact that there might be free positions at the low end of the array where elements have previously been removed from the queue the "drifting queueproblem can be solved by pretending that the array is circular and so allow the queue to continue directly from the highest-numbered position in the array to the lowest-numbered position this is easily implemented