Question: the language is Java. Thank you 5. Assume we use a max-on-top heap to implement a priority queue: we insert elements into the queue and

the language is Java. Thank you 5. Assume we use a max-on-topthe language is Java. Thank you

5. Assume we use a max-on-top heap to implement a priority queue: we insert elements into the queue and remove elements in the order of their priority (max priority first). a) Give an example scenario showing that for a classic max-on-top heaps considered in class, elements within a given priority may not be removed in FIFO order. In other words, give a scenario where elements x and y have the same priority, x is inserted into the heap before y, but then removeMax invocations remove y before x. (3 points) b) Assume we want to enhance our heap implementation to ensure that we remove elements in the FIFO order within a given priority. In other words, for any two elements with the same priority, the element that was inserted first will be removed first. The methods involved in the heap insertion and removal are "void insert(T item)", "T removeMax(", "void siftUp(int i)", and "void siftDown(int i)". Write these methods to support the above functionality. (3 points) 5. Assume we use a max-on-top heap to implement a priority queue: we insert elements into the queue and remove elements in the order of their priority (max priority first). a) Give an example scenario showing that for a classic max-on-top heaps considered in class, elements within a given priority may not be removed in FIFO order. In other words, give a scenario where elements x and y have the same priority, x is inserted into the heap before y, but then removeMax invocations remove y before x. (3 points) b) Assume we want to enhance our heap implementation to ensure that we remove elements in the FIFO order within a given priority. In other words, for any two elements with the same priority, the element that was inserted first will be removed first. The methods involved in the heap insertion and removal are "void insert(T item)", "T removeMax(", "void siftUp(int i)", and "void siftDown(int i)". Write these methods to support the above functionality. (3 points)

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!