Jump to content

Data Structure Help [Java]


Recommended Posts

Posted (edited)

So I have a problem where I have a set of objects with two fields. I need to be able to get the min object of the set at a fast time (using a custom comparator). The problem is, when I get the min object set, it changes the fields of some objects in my original set. Thus, the ordering of the set needs to be changed when I am done with the min object. 

To me it seems obvious to use a priority queue with a custom comparator, the problem is, the Priority Queue in Java doesn't have a change or decrease key operation. I have tried looking for other implementations online for a priority queue that uses a comparator with the decrease key operation but I cannot find one. Any help would be greatly appreciated at to how to approach this problem? 

Edited by Qubit
Posted
5 minutes ago, dreameo said:

Delete entries that have changed and re enter them in the priority queue for it to remain ordered. 

Problem is, the remove function in a PQ is linear and every time a min get removed, multiple objects get updated in the PQ. Thus many iterations of the whole PQ is needed

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...