Step by step
The question
Question: find the shortest path from A to E.
1 Draw the graph
The numbers on the edges are lengths: how far it is along each edge.
2 Start the table
A table: a column for each vertex.
Each cell holds how far it is from A so far, and, small, the vertex we came from.
A is 0 from itself.
The others are not reached yet: ∞, as far as can be.
Careful!
Fewer edges is not the same as shorter.
We must add the lengths.
3 Round 1
The smallest open number is A: 0.
Nothing can beat it any more, so A is final.
B: 0 plus 2 is 2.
D: 0 plus 3 is 3.
The next row: the new numbers, the rest copied down.
4 Round 2
The smallest open number is B: 2.
Nothing can beat it any more, so B is final.
C: 2 plus 2 is 4.
D: 2 plus 1 is 3, not less than 3.
Keep 3.
The next row: the new numbers, the rest copied down.
5 Round 3
The smallest open number is D: 3.
Nothing can beat it any more, so D is final.
E: 3 plus 4 is 7.
The next row: the new numbers, the rest copied down.
6 Round 4
The smallest open number is C: 4.
Nothing can beat it any more, so C is final.
E: 4 plus 2 is 6, less than 7.
Change it.
The next row: the new numbers, the rest copied down.
7 Round 5
The smallest open number is E: 6.
Nothing can beat it any more, so E is final.
8 The route back
Go back with the small letters: E from C, C from B, B from A.
That is the route.
The shortest path is A, B, C, E, length 6.
9 Check
Add the lengths along the route: 2 + 2 + 2 = 6.
Right!
The route with the fewest edges, A, D, E, is 7: longer.
Right!
Let's look back.
First: draw the graph.
Then: start the table.
Then: round 1.
Then: round 2.
Then: round 3.
Then: round 4.
Then: round 5.
Then: the route back.
Last: check.