I was trying to implement Dijkstra's algorithm using a priority queue
in Java..
Unfortunately it was returning wrong results...I have tracked down the problem.
Here's the Problem..After inserting the node weights into the queue,I am modifying those node weight,but when i try to remove the element from the priority queue ,its returning the historical minimum (minimum at the time of insertion).remove()
doesn't know that the priority queue has been modified..Any help would be greatly appreciated ...Thanks!
Note:i can add the source code if required
This SO question should help you. The drawback with the PriorityQueue in Java is that the if an inserted element value changes, the priority queue is not re-constructed to reflect the new order. Thus you would have to remove and re-insert the changing elements to satisfy your use case.