Do you need to implement an "update priority" method for a Priority Queue when using it in Dijkstra's algorithm?
14:48 13 May 2026

In Dijkstra's algorithm, you need to select the nodes with the smallest distance (distance = priority in the Priority Queue which is implemented by a MIN heap)

You also need to update the distances of nodes, which is the same thing as updating their priorities.

If you have a node with id = A and distance / priority = 5, and we want to relax node "A" in Dijkstra's algorithm so that the distance is equal to 2, then can't we just add a new entry to the priority queue ("A", 2). Instead of calling any sort of "updatePriority" method on the Priority Queue

Now the priority queue will have two entries for the node with id = A, however only the A with priority = 2 will come up before A with priority = 5

Is my idea correct or is there something I'm not seeing?

Thank you

algorithm data-structures priority-queue dijkstra heap