Shortest-Path Calculator
Find the shortest path in a weighted graph using Dijkstra’s algorithm for nonnegative edge weights.
Calculate
Enter one edge per line: from to weight. Weights must be nonnegative. This calculator treats edges as undirected by default.
What this calculator teaches
Shortest-path algorithms find the lowest-cost route through a weighted graph. Dijkstra’s algorithm is the classic method when all edge weights are nonnegative.
This appears in maps, networking, routing, scheduling, games, and optimization.
Formula & Symbols
| Concept | Formula | Meaning |
|---|---|---|
| Path cost | sum of edge weights | The total cost of traveling along a path. |
| Dijkstra update | dist[v] = min(dist[v], dist[u]+w) | Relax edges from the current closest vertex. |
Step-by-Step Examples
- A-C costs 2 and C-B costs 1.
- A-B directly costs 4.
- The algorithm keeps the smaller cost A-C-B = 3.
Where students use this
Common Mistakes to Avoid
Dijkstra’s algorithm does not support negative edge weights.
A node is final only when it is selected as the current minimum unvisited node.
The shortest path has the smallest total weight, not always the fewest edges.
Frequently Asked Questions
Related Math Calculators
Formula Explorer connections
Interpretation: This formula or algorithm measures graph structure, traversal, reachability, path cost or network connectivity. Assumption: Specify whether the graph is directed or weighted and whether negative edges, cycles or disconnected components are allowed by the chosen algorithm.