Question: Your main objective is to implement an operation public void requeue(T x) Which repositions x in the heap based on its priority. Whereas enqueue swaps

Your main objective is to implement an operation public void requeue(T x) Which repositions x in the heap based on its priority. Whereas enqueue swaps a value upwards and dequeue swaps a value downwards, requeue may need to swap a value from somewhere in the middle of the heap tree upwards or downwards (but only in one direction). Critically, this operation should run in worst-case log(n) time just as enqueue and dequeue, (where n is the size of the heap). Searching the heap for x is O(n). This means we can't look for where x is stored. Instead, we need to maintain information about where in the heap each object is stored. This information needs to be updated: each time an enqueue or dequeue occurs, the indices of other objects in the heap may also be affected because of the swappings needed. Thus we require that *all objects to be stored inside the heap to implement the following interface, which you will find in HeapValue.java: public interface HeapValue extends Comparable { int getIndex(); void setIndex(int x); // int compareTo(T x); // inherited from Comparable }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!