EN
My tools

Dijkstra Shortest Path Calculator

Run Dijkstra's algorithm on an edge list: shortest distances and paths from a source, a step-by-step table of visits and updates, directed or undirected.

Shortest distance from s to x
9
Path
s → y → t → x
Nodes reachable from s
5
of 5

Each step visits the unvisited node with the smallest known distance (ties: the node that appeared first in the list) and updates its neighbours.

Shortest paths from s
NodeDistancePreviousPath
s0(start)s
t8ys → y → t
y5ss → y
x9ts → y → t → x
z7ys → y → z
Steps
StepVisitDistanceUpdatedstyxz
1s0t = 10, y = 50105∞∞
2y5t = 8, x = 14, z = 7✓85147
3z7x = 13✓8✓137
4t8x = 9✓8✓9✓
5x9—✓✓✓9✓
My tools →
Advertisement

Dijkstra's algorithm finds the shortest paths from one node to every other node in a graph whose edge weights are not negative — the basis of route planners, network routing and many textbook exercises. Enter the edges as a list, pick the start (and optionally the end) node, and this calculator gives every shortest distance and path plus a step-by-step table of which node is visited and which distances are updated, the way the algorithm is traced by hand.

How to use this tool

  1. Enter one edge per line: from, to and weight (A B 4).
  2. Tick "Directed" for one-way edges, or leave it off for two-way edges.
  3. Type the start node and, optionally, the end node.
  4. Read the distance and path, the table for all nodes, and the steps.

Formula

repeat: visit the unvisited node u with the smallest d(u); for each edge u → v of weight w: if d(u) + w < d(v), set d(v) = d(u) + w and prev(v) = u

All distances start at ∞ except the start node (0). Once a node is visited its distance is final, which is only guaranteed when no weight is negative — so negative weights are refused (Bellman–Ford handles them). Paths are rebuilt by following prev back to the start. Ties go to the node listed first. Parallel edges are allowed; the cheaper one wins.

Example

The sample is the directed graph from Figure 24.6 of Introduction to Algorithms (CLRS). From s, the visits are s (0), y (5), z (7), t (8) and x (9). The shortest route to x is s → y → t → x with length 9: 5 + 3 + 1. The direct-looking s → t edge (10) loses to s → y → t (8).

Frequently asked questions

Why can't Dijkstra handle negative weights?

It fixes a node's distance as soon as the node is visited. A negative edge found later could make that distance smaller, so the answer would be wrong. Use Bellman–Ford instead.

Does the order of the edges matter?

Only for ties: when two unvisited nodes have the same distance, the one that appeared first in the list is visited first. The distances themselves never depend on the order.

What does "unreachable" mean?

No path leads from the start node to that node — in a directed graph the edges may all point the wrong way.

Sources

Last updated:

Cite or embed this tool
APA

kakaoCalc. (2026, November 8). Dijkstra Shortest Path Calculator. https://kakao.mobile/tools/dijkstra-visualizer/

MLA

“Dijkstra Shortest Path Calculator.” kakaoCalc, 8 Nov. 2026, kakao.mobile/tools/dijkstra-visualizer/.

Paste this code into your page. The widget runs in your visitors' browsers, shows no ads and keeps a link back to this page. Embedding terms

Advertisement