Dijkstra Shortest Path Calculator screenshot

Dijkstra Shortest Path Calculator

Find the cheapest route between two nodes of a weighted undirected graph, with the path and the algorithm's settle order printed beside the distance.

Privacy First
0 Runs
Updated 2026-11-22
Runs in your browser
No sign-up, no upload
Exact on the weights given

Dijkstra Shortest Path Calculator

Find the cheapest route between two nodes of a weighted undirected graph, with the path and the algorithm's settle order printed beside the distance.

How this page computes

The edge list becomes an undirected adjacency map, where a repeated pair keeps its lighter weight. The search then settles one node per round and relaxes the edges leaving it.

The path is reconstructed from the predecessor each node recorded when its distance improved, so the printed route and the printed distance come from the same traversal.

The calculation runs entirely in this browser tab; nothing is uploaded.

The page runs Dijkstra's algorithm from the source you name and prints the cheapest route to the target with its total weight. On A-B 4, B-C 2, A-C 5 the answer is the direct A to C edge at 5, not the two-hop route at 6, and the printed path says so.

Weights are distances or costs, so they cannot be negative. The page refuses a negative weight by line number instead of producing a distance that Dijkstra cannot guarantee.

How to use Dijkstra Shortest Path Calculator

List the edges one per line, type the source and the target, then press Run. Node names are whatever you wrote, so "home", "office" and "A" all work as long as each line uses them.

The output gives the distance, the path node by node, how many vertices were settled before the target, and how many edge relaxations were performed — the last two make the algorithm's work visible rather than asserted.

Why settling the nearest node is enough

Dijkstra keeps a tentative distance for every node, starts at 0 for the source and infinity elsewhere, and repeatedly settles the unsettled node with the smallest tentative distance. Because every weight is non-negative, no later route can improve a settled node, which is the step that makes the answer final.

Each time a node is settled, every edge leaving it relaxes its neighbour: if the settled distance plus the edge weight is smaller than the neighbour's current value, the neighbour takes the new value and records where it came from. The path is then read backwards from the target.

What to Expect

Best for

  • The cheapest route in a road, network or cost graph
  • Checking a hand-worked Dijkstra table
  • Seeing which nodes were settled before the target

Not ideal for

  • Graphs with negative weights, which need Bellman-Ford
  • All-pairs distances, which this page does not print
  • An unreachable target, which the page refuses rather than answering with infinity

What this tool keeps

  • Every node name, weight and the direction of the edge list

What may need cleanup

  • Nothing: the distance and the path are final

Common errors

  • A negative weight is refused with its line number
  • A source or target that is not in the graph is refused with the node list
  • An unreachable target is refused with the reason

Example use cases

  • Find the cheapest A to C route in a small road graph
  • Check that the two-hop route is cheaper than the direct one
  • See the settle order for a teaching example

Sample input

edges A-B 4, B-C 2, A-C 5; source A, target C

Sample output

shortest distance 5 along A -> C

Who this is for

  • Students learning graph search
  • Readers checking a route cost

Frequently asked questions

Why is the direct edge cheaper than the two-hop route?

Because A to C is 5 while A to B plus B to C is 4 + 2 = 6. Dijkstra compares totals, not hop counts, so the single edge wins and the printed path has two nodes.

Can the weights be decimals?

Yes. A decimal weight is a double, and the total is printed to six decimals with the same arithmetic the browser uses. A negative weight is refused, because Dijkstra's proof needs non-negative edges.

What if the target cannot be reached?

The page refuses and says the target sits in a different connected component. Returning infinity as a distance would look like an answer, and there is no path to print.

Developer program

Build custom tools for your store

Join the SDK program to create useful ecommerce utilities for your store.