In: Computer Science
Discuss the relative efficiency of the enqueue and dequeue operations for an array-based queue implemented with a fixed-front approach as opposed to a floating-front approach.
A queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue).
For an array based queue we could implement enqueue by adding the new item at the end of the array and implement dequeue by saving the first item in the array, moving all other items one place to the left, and returning the saved value. The problem with this approach is that, although the enqueue operation is efficient, the dequeue operation is not, it requires time proportional to the number of items in the queue.
Now relative efficiency of the enqueue and dequeue operations for an array-based queue implemented with a fixed-front approach as opposed to a floating-front approach------>
Fixed Front:
It involves more work because the system has to keep track of
both the rear and front and move all elements of the Queue up
towards the front.
Floating Front:
It involves less work because instead of the System moving the elements forward towards the front, enqueue and dequeue can add or remove elements from either the front or the back and the elements do not move. Only the front and back move. Because of the fact that the elements do not move, floating front is much more efficient.