- Notifications
You must be signed in to change notification settings - Fork 31.1k
Open
Description
In the Dijkstra algorithm, when a shorter path to a neighbor is found, the neighbor's priority in the priority queue should be updated regardless of whether it is already present in the queue.
In this code, the priority is only changed if queue.hasValue(neighbor) returns true. However, if a neighbor is not yet in the queue, it is added; but if it's already present, the code changes its priority.
This logic is correct as long as queue.changePriority works as intended, but it could be fragile if there are issues in the PriorityQueue implementation (such as not truly updating priorities or not handling duplicates). If the PriorityQueue does not remove duplicates, a neighbor may exist multiple times in the queue with different priorities.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels