Question

In: Computer Science

Discuss the relative efficiency of the enqueue and dequeue operations for an array-based queue implemented with...

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.

Solutions

Expert Solution

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.


Related Solutions

In Java: Initiate empty queue of strings and recreate .isempty, .size, .dequeue, .enqueue methods. //You may...
In Java: Initiate empty queue of strings and recreate .isempty, .size, .dequeue, .enqueue methods. //You may not use the original methods of the stack api to answer. You may not add any more fields to the class. import java.util.NoSuchElementException; import edu.princeton.cs.algs4.Stack; public class StringQueue {    //You may NOT add any more fields to this class.    private Stack stack1;    private Stack stack2;    /**    * Initialize an empty queue.    */    public StringQueue() { //TODO   ...
Suppose you start with an empty queue and perform the following operations: enqueue 1, enqueue 2,...
Suppose you start with an empty queue and perform the following operations: enqueue 1, enqueue 2, dequeue, enqueue 3, enqueue 4, dequeue, enqueue 5. What are the resultant contents of the queue, from front to back? Group of answer choices 1, 2, 3, 4, 5 1, 3, 5 1, 2, 3 3, 4, 5 Assume you are using the text's array-based queue and have just instantiated a queue of capacity 10. You enqueue 5 elements, dequeue 4 elements, and then...
The following sequence of operations essentially leaves a queue unchanged. Group of answer choices enqueue followed...
The following sequence of operations essentially leaves a queue unchanged. Group of answer choices enqueue followed by dequeue dequeue followed by enqueue two enqueues followed by two dequeues two isEmptys followed by two isFulls A standard linked list provides a good implementation of a "Deque". Group of answer choices True False The main thread of a Java program cannot generate additional threads. Group of answer choices True False The text's link-based queue is being used and holds an empty queue....
Assume you have a stack and a queue implemented using an array of size 4. show...
Assume you have a stack and a queue implemented using an array of size 4. show the content of the array for the stack (then the queue) for the following operations: (for the queue replace push by add and pop by remove; keep in mind that the queue uses a circular array): push(-3), push(-5), push(-9), push(-10), pop(), pop(), push(-13), pop(), push( -15), push(-17). java code
For an organisation that has recently implemented a few IT systems to support business operations, discuss...
For an organisation that has recently implemented a few IT systems to support business operations, discuss one (1) possible benefit that may be derived. Also discuss one (1) problem that may arise. How might this problem be addressed?
Problem A. The pseudocode as below illustrates the basic push() and pop() operations of an array-based...
Problem A. The pseudocode as below illustrates the basic push() and pop() operations of an array-based stack, where top is initialized as 0 when the stack is empty. Assuming that at a given moment, SIZE is equal to 20, top is equal to 8, this code is used in a concurrent environment (top and stack[] are in shared memory section), process P0 is about to call push() and process P1 is about to call pop() concurrently a. Which variable has...
Classify the operational measures as time-based, quality-based, or efficiency-based. Discuss the significance of each category for...
Classify the operational measures as time-based, quality-based, or efficiency-based. Discuss the significance of each category for lean manufacturing. If there is no effect select "Not applicable". Using Net Benefit to Evaluate Risk Response Alternatives Cooper Movie Studio Corp. makes movies and is interested in lowering its operating costs for the following year, while maintaining the high quality and appeal of its movies. Cooper’s management is concerned about the additional costs the company would have to incur if new industry regulation...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT