Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedthe 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

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Advances In Databases And Information Systems Second East European Symposium Adbis 98 Poznan Poland September 1998 Proceedings Lncs 1475

Authors: Witold Litwin ,Tadeusz Morzy ,Gottfried Vossen

1st Edition

3540649247, 978-3540649243

More Books

Students also viewed these Databases questions