Steply

Shortest path from A to E: AB 2, BE 9, AC 4, CD 3, DE 1, BC 1

Step by step, with the reason for every step · Shortest path · Discrete Math

Step by step

The question

Question: find the shortest path from A to E.

from A to E: AB 2, BE 9, AC 4, CD 3, DE 1, BC 1

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.

0

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.

Careful: not A, B, E = 2 + 9 = 11 ✗

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.

C: 0 plus 4 is 4.

from A: B: 0 + 2 = 2, C: 0 + 4 = 4

The next row: the new numbers, the rest copied down.

0
2A
4A
∞
∞

4 Round 2

The smallest open number is B: 2.

Nothing can beat it any more, so B is final.

C: 2 plus 1 is 3, less than 4.

Change it.

E: 2 plus 9 is 11.

from B: C: 2 + 1 = 3 < 4, E: 2 + 9 = 11

The next row: the new numbers, the rest copied down.

–
2A
3B
∞
11B

5 Round 3

The smallest open number is C: 3.

Nothing can beat it any more, so C is final.

D: 3 plus 3 is 6.

from C: D: 3 + 3 = 6

The next row: the new numbers, the rest copied down.

–
–
3B
6C
11B

6 Round 4

The smallest open number is D: 6.

Nothing can beat it any more, so D is final.

E: 6 plus 1 is 7, less than 11.

Change it.

from D: E: 6 + 1 = 7 < 11

The next row: the new numbers, the rest copied down.

–
–
–
6C
7D

7 Round 5

The smallest open number is E: 7.

Nothing can beat it any more, so E is final.

8 The route back

Go back with the small letters: E from D, D from C, C from B, B from A.

E from D, D from C, C from B, B from A

That is the route.

The shortest path is A, B, C, D, E, length 7.

= A, B, C, D, E: length 7

9 Check

Add the lengths along the route: 2 + 1 + 3 + 1 = 7.

Right!

2 + 1 + 3 + 1 = 7

The route with the fewest edges, A, B, E, is 11: longer.

Right!

fewest edges A, B, E: 2 + 9 = 11 > 7

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.

Answer
= A, B, C, D, E: length 7

Your turn

Try this one yourself, then check:

from A to E: AB 3, BE 10, AC 4, CD 3, DE 1, BC 2
Show the answer
A, C, D, E, length 8

More from Shortest path

The whole lesson: Shortest path →