Problem solved in full
-
Node 1 one edge from the source at a cost of 4 5 steps
Node 1 is one edge from the source, at a cost of 4 — and the algorithm reports its distance as 3. Work through the settling order and find where the 3 comes from.
-
Dijkstra settles nodes in order of distance, never revisiting. That ordering is the whole algorithm and the whole proof: when a node is settled, no cheaper route to it can exist, because any such route would have to pass through an unsettled node that is already further away.
-
From the source the two direct edges give tentative distances of 4 and 2. Neither is final yet — they are upper bounds.
-
The nearest is node 3 at 2, so it settles first. Relaxing its edges finds a route to node 1 costing 2 + 1 = 3, which beats the direct edge of 4. This is the step that answers the question: the cheapest way to a neighbour need not be the edge to it.
-
Node 1 settles at 3, and relaxing from there reaches node 2 at 8.
-
Node 4 is reachable at 8 through node 3, and the alternative through node 2 costs 8 + 3 = 11, so the shorter one stands.
Answer
The tool prints distances of 3, 8, 2, 8 and a shortest path of 0 → 3 → 4. The lesson is in node 1: a direct edge is not a shortest path, and greedy settling is what makes finding that out cheap rather than exponential. The guarantee has one requirement, though — non-negative weights. With a negative edge, a node settled early can later be improved, and the proof in step 1 collapses. Click the negative-edge preset and watch it fail in both directions at once: node 3 comes back at −1, which is not a distance any route produces, and the path reconstruction gives up entirely with “no path — the predecessors form a loop”. Wrong numbers and no route, from an algorithm that is provably correct the moment every weight is non-negative.
-
References (2)
- The three-page paper, in which the shortest-path algorithm is the SECOND of the two problems: E. W. Dijkstra, "A note on two problems in connexion with graphs." Numerische Mathematik 1, 269–271, 1959.
- The algorithm the negative-edge preset points you to, which tolerates negative weights and detects a negative cycle instead of answering as though there were none: R. Bellman, "On a routing problem." Quarterly of Applied Mathematics 16(1), 87–90, 1958.