Shortest Path (Dijkstra) Calculator
Work out shortest path (dijkstra) instantly with clear inputs, formula shown and shareable results.
About Shortest Path (Dijkstra) Calculator
Dijkstra's algorithm settles vertices in order of increasing distance from the source, relaxing each outgoing edge as it goes. Non-negative weights guarantee that once a vertex is settled its distance is final.
Formula
Relaxation
if dist(u) + w(u,v) < dist(v) then dist(v) = dist(u) + w(u,v)
Worked example
With the default values below, Shortest Path (Dijkstra) Calculator returns Shortest distance of 20.000000. Change any input above and every figure here is recalculated in your browser.
Inputs used
- Edges as from,to,weight triples
- 1,2,4 1,3,2 2,3,5 2,4,10 3,5,3 5,4,4 4,6,11
- Start vertexminimum 1
- 1
- End vertexminimum 1
- 6
Results
- Shortest distance
- 20.000000
- Shortest path
- 1 → 3 → 5 → 4 → 6
- Number of hops
- 4
- Vertices in the graph
- 6
Step by step
- 1Values used
- 2Relaxation
- 3Shortest distance= 20.000000
- 4Shortest path= 1 → 3 → 5 → 4 → 6
- 5Number of hops= 4
- 6Vertices in the graph= 6
Assumptions and limits
- The result is derived only from the 3 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
- Figures are rounded for display to 6 decimal places, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
Frequently Asked Questions
For the sample graph from 1 to 6?
The route 1 → 3 → 5 → 4 → 6 costs 2 + 3 + 4 + 11 = 20, cheaper than going via vertex 2.
Why must weights be non-negative?
A negative edge could improve a distance already declared final. Bellman-Ford handles that case instead.
Related Calculators
You might also need
- Catalan Path Counting CalculatorAlso in Discrete Math, Logic & Number Theory
- Discrete Logarithm CalculatorAlso in Discrete Math, Logic & Number Theory
- Adjacency Matrix CalculatorAlso in Discrete Math, Logic & Number Theory
- Base 64 Value CalculatorAlso in Discrete Math, Logic & Number Theory
- Bell Number CalculatorAlso in Discrete Math, Logic & Number Theory
- Binary To Decimal CalculatorAlso in Discrete Math, Logic & Number Theory
