← The collection

Dijkstra’s Algorithm.

Trace tentative distances through a weighted network until the cheapest route is certified.

Interactive experimentintuitiveField note ·
INTERACTIVE EXPERIMENT / M31

Dijkstra’s Algorithm

Trace tentative distances through a weighted network until the cheapest route is certified.

PLAY & EXPLAIN

Find the cheapest route from A to E. Each step settles the unvisited node with the smallest tentative distance, then relaxes its outgoing edges. All weights are nonnegative.

2514137ABCDE
Tentative route costs from A
NodeCostState
A0Tentative
B∞Tentative
C∞Tentative
D∞Tentative
E∞Tentative

A tentative distance can still improve before its node is settled.

The graph is small, static and has nonnegative weights; negative edges invalidate the settling argument.

THE SHORT VERSION

Dijkstra’s Algorithm, explained.

Dijkstra’s algorithm finds shortest paths from a source in a graph with nonnegative edge weights by repeatedly settling the smallest tentative distance.

01 / THE MECHANISM

Why it happens

An authored five-node undirected graph starts at A. Each step settles the lowest-cost unvisited node and relaxes adjacent edges. The least-cost A-to-E route is A–B–C–D–E with total weight seven.

Dijkstra’s algorithm finds shortest paths from a source in a graph with nonnegative edge weights by repeatedly settling the smallest tentative distance.

Read the result

Tentative distances are upper bounds that can improve. Settled distances are certified only because every edge weight is nonnegative.

02 / FOLLOW IT THROUGH

A worked example

A cheap route with several edges

  1. Settle A and compare its direct tentative costs to B and C in the weighted graph.

  2. Settle B to improve C through the cheaper two-edge route, then continue through C and D.

  3. Settle E at total cost seven and trace A–B–C–D–E rather than counting connections as if every edge had equal cost.

OPTIONAL DEEPER DETAILGo deeper: inside the model

Inside this model

An authored five-node undirected graph starts at A. Each step settles the lowest-cost unvisited node and relaxes adjacent edges. The least-cost A-to-E route is A–B–C–D–E with total weight seven.

03 / BEYOND THE EXPERIMENT

Where this idea is useful

A practical use

Use weighted travel cost rather than the number of connections when routes differ in time or expense.

CHECK YOUR INTUITION

A common misconception

THE TEMPTING CONCLUSION

“The path with the fewest connections is always cheapest.”

THE MORE USEFUL DISTINCTION

Unequal edge weights make total weight, rather than edge count, the relevant objective. A longer sequence can have a lower cost.

What this explanation leaves out

  • The graph is small, static and has nonnegative weights; negative edges invalidate the settling argument.
ONE MORE QUESTION

Can this settling logic handle negative edges?

No. A negative edge can later create a cheaper route to a supposedly final node, invalidating the argument used here.

TAKE THE IDEA WITH YOU

Are you minimising the number of steps or their actual accumulated cost?

Associated thinkers

Associated withEdsger Dijkstra ↗

Associations marked provisional are awaiting source review.

Further reading

Explore the original research or the teaching reference behind this experiment.