What data structure to use when I need to
- access an object by priority – to dequeue
- access an object by name/id to update the priority
With Java’s PriorityQueue, I can’t access a node directly by its name/id property can I?
I was thinking along the lines of use a priority queue, plus a TreeMap so I can search by name in log(n) time, then modify the priority. But I doubt the Queue will know of that? In that case, I need to remove and re-add the node? Is that worth the overhead? What complexity is it to remove/re-add a node?
Yes.
That depends on your requirements. Only you know that.
Insert and remove from a PriorityQueue is O(log n).