Skip to content

Potential Inefficiency and Missed Priority Updates in Dijkstra's Algorithm Implementation #2056

Description

@Imran-imtiaz48

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions