Jump to content

Data Structure Help [Java]


Qubit

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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