Problem Solving

Dijkstra’s Algorithm

A child marks progressively farther junctions on a route map.

Dijkstra’s Algorithm definition

Dijkstra’s algorithm computes shortest-path distances from a start vertex in a graph with nonnegative edge weights.

In Spanish
algoritmo de Dijkstra
Topic
Graph algorithms and networks

Dijkstra’s Algorithm in a picture

Dijkstra’s Algorithm diagramA direct route to C of length 9 improves to 5 when the route through B has lengths 2 and 3.Start at A with distance 0First estimates: B = 2 and C = 9Settle B at distance 2Try B to C, which costs 3Update C to 5The route through B is shorter
A direct route to C of length 9 improves to 5 when the route through B has lengths 2 and 3.

How it works

Set the start’s tentative distance to zero and the others to infinity. Settle an unsettled vertex with the smallest tentative distance, then improve its neighbors’ estimates when going through it gives a smaller value. Repeat until every reachable vertex is settled.

Worked examples

Start at A with edges A → B of weight 3 and A → C of weight 8. Which settles next?

B, since its tentative distance is 3.

If B → C costs 2, what is the new estimate for C?

3 + 2 = 5, improving on 8.

What distance stays for an unreachable vertex?

Infinity in the usual initialization and representation.

Common mistake

Use a smallest tentative total distance from the start. Selecting the smallest individual edge anywhere is a different rule.

Quick check

Which edge-weight condition supports Dijkstra’s usual guarantee?

Can a weight be zero?

Show answer

Yes.

What is updating a neighbor’s estimate commonly called?

Show answer

Relaxing the edge.

Sources

Flashcard

Dijkstra’s Algorithm

Reveal the definition

Dijkstra’s algorithm computes shortest-path distances from a start vertex in a graph with nonnegative edge weights.

Effortless Math. “Dijkstra’s Algorithm.” Math Dictionary.