Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How many multiples of 4 are there between 10 and 250?

Answered: 1 week ago