Meaning and conditions
Finite directed graph, additive nonnegative edge weights and a defined source. Our calculator uses exactly four vertices and five existing edges with integer weights between 0 and 100.[1][2]
Initially d(v) is an upper bound: every finite candidate corresponds to a found path. Unreachable means infinite, not zero. The fixed teaching graph always has at least one s–t route.[1]
Step-by-step reasoning
Suppose the smallest open vertex u still had a shorter undiscovered route. That route must cross from finalized to open vertices. At its first open vertex an equally small or smaller candidate would already have been supplied. Nonnegative remaining edges cannot lower the cost below that candidate, contradicting the selection of u.[1]
Edge relaxation only updates an improved candidate.[1]
Adjacency lists and a suitable priority queue give a usual O((|V|+|E|) log |V|) bound; the chosen data structure determines the exact variant. This four-vertex calculator shows decisions, not measured hardware time.[1]
- Fix directed edges, a common additive cost unit and source s. Require nonnegative weights; zero denotes an existing free edge. Initialize d(s)=0, all other distances to ∞ and predecessors as empty.
- Remove the open vertex u with smallest tentative d(u). This selection finalizes its distance; discovery alone does not. A fixed ordering may break ties because zero-cost remaining edges cannot create a smaller distance.
- For each outgoing edge u→v, test d(u)+w(u,v). A strict improvement updates distance, predecessor and priority. In the first example, a improves b from 5 to 3; b then lowers t from 8 to 5.
- Repeat extraction and relaxation until the target is finalized or no reachable open vertex remains. Reconstruct the path backward through predecessors and verify its edge sum. The fixed teaching graph gives s→a→b→t with cost 5; different optimal routes need not share one predecessor chain.
Weighted cost rather than fewest edges
Final distances from s
Free with a Quanta account. Your download stays ready after registration.
Two fully worked original examples
Improve a tentative distance
- Given
- Directed edges s→a 2,s→b 5,a→b 1,a→t 6,b→t 2; start s.
- Find
- Find the distance and predecessor chain to t.
Initialize only the source with a finite distance.
Remove s, then a with the smallest open distance 2.
b at distance 3 improves the target. Only afterward is t finalized at 5.
Result: Predecessors t←b←a←s yield s→a→b→t with cost 5.
Check: The other complete routes cost 2+6=8 and 5+2=7. The minimum is indeed 5.
A zero-cost edge is allowed
- Given
- Same five edges, now weights sa=0,sb=4,ab=2,at=7,bt=1.
- Find
- Check whether the zero-cost edge violates the reasoning.
s is finalized first; its zero edge discovers a at distance 0 as well.
The route through a improves b, which then improves the target.
The edge sum is calculated without requiring strict positivity.
Result: The shortest route costs 3. Zero is nonnegative and therefore allowed.
Check: s→a→t costs 7 and s→b→t costs 5. The three-edge route is cheaper than both two-edge routes.
Recall the method later with the formula’s flashcards.
11 flashcards · English materials
Already have an account? Sign in for flashcardsAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Five exercises with solutions
Calculate · Foundation
Directed edges s→a:3, s→b:8, a→b:2, a→t:9, b→t:1. Find the shortest distance s→t.
Show hint
Compare the three s–t routes available in the fixed graph.
Learning goal: Add and minimize weighted path costs.
Rearrange · Application
Replace ab=1 in the first example by x≥0. For which x is s→a→b→t no more expensive than any other route?
Show hint
The alternatives still cost 8 and 7.
Learning goal: Determine a parameter range preserving an optimal route.
Interpret · Foundation
After the first step b is discovered at distance 5. Is that value already final?
Show hint
a is still open with distance 2.
Learning goal: Distinguish discovery from finalization.
Error analysis · Application
Someone adds 10 to every edge to remove negative weights and claims shortest paths remain unchanged. Check this using the first example.
Show hint
Routes with different edge counts receive different additions.
Learning goal: Refute an invalid model transformation with a counterexample.
Transfer · Application
For four vertices use sa=1,sb=2,ab=5,at=8,bt=1. Does minimizing edge count automatically minimize cost?
Show hint
There are two different two-edge routes.
Learning goal: Match algorithm choice to the actual objective.
Check your understanding with the formula’s reference test.
8 test questions · English materials
Already have an account? Sign in for the testAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Model limits and next steps
Negative edges invalidate the selection argument in general. A shortest-path tree minimizes routes from one source, not the total weight of all tree edges.[1][2]
BFS and DFS explain unweighted exploration. A minimum spanning tree instead optimizes total connection cost; Big O describes computational effort.
Sources for this explanation
Quanta · Updated November 21, 2026
- Stanford CS221 States-based Models — Graph search; Uniform cost search; Correctness theorem
- Baden-Württemberg teacher training: Data and Coding, solutions section 6, Dijkstra algorithm (M. Klein, 2019; German-language PDF, pp. 3-5)
Editorial responsibility: Quanta Study editorial team
Review scope
This explanation, 2 worked examples and 5 exercises are available in German and English. Structure, source references and mathematical notation undergo automated checks. Calculations, model assumptions and both language versions receive a separate AI review.
An independent, named human subject review has not yet been documented. Our exercise numbers are worked examples, rather than measurements published by the cited sources.
Editorial responsibility, sources and methodsChange history
- Added four concrete learning steps from initialization through path verification and localized the English short notation.
- Created a DE/EN author draft with a bounded model, original graphic, two examples and varied solved exercises.
Cite this reference page
Quanta. Dijkstra’s algorithm for weighted shortest paths. Updated November 21, 2026. https://quanta-study.de/en/formula-sheet/dijkstra-kuerzeste-wege
When citing a specific scientific statement, also cite the specialist source linked to that statement.