Steply

Shortest path from A to F: AB 6, AC 8, AF 15, BC 9, BD 14, CD 10, CF…

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 F.

from A to F: AB 6, AC 8, AF 15, BC 9, BD 14, CD 10, CF 3, DE 5, EF 8

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, F = 15 = 15 ✗

3 Round 1

The smallest open number is A: 0.

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

B: 0 plus 6 is 6.

C: 0 plus 8 is 8.

F: 0 plus 15 is 15.

from A: B: 0 + 6 = 6, C: 0 + 8 = 8, F: 0 + 15 = 15

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

0
6A
8A
∞
∞
15A

4 Round 2

The smallest open number is B: 6.

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

C: 6 plus 9 is 15, not less than 8.

Keep 8.

D: 6 plus 14 is 20.

from B: C: 6 + 9 = 15 ≥ 8, D: 6 + 14 = 20

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

–
6A
8A
20B
∞
15A

5 Round 3

The smallest open number is C: 8.

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

D: 8 plus 10 is 18, less than 20.

Change it.

F: 8 plus 3 is 11, less than 15.

Change it.

from C: D: 8 + 10 = 18 < 20, F: 8 + 3 = 11 < 15

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

–
–
8A
18C
∞
11C

6 Round 4

The smallest open number is F: 11.

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

E: 11 plus 8 is 19.

from F: E: 11 + 8 = 19

7 The route back

Go back with the small letters: F from C, C from A.

F from C, C from A

That is the route.

The shortest path is A, C, F, length 11.

= A, C, F: length 11

8 Check

Add the lengths along the route: 8 + 3 = 11.

Right!

8 + 3 = 11

The route with the fewest edges, A, F, is 15: longer.

Right!

fewest edges A, F: 15 = 15 > 11

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: the route back.

Last: check.

Answer
= A, C, F: length 11

Your turn

Try this one yourself, then check:

from A to F: AB 7, AC 8, AF 16, BC 8, BD 14, CD 9, CF 2, DE 5, EF 8
Show the answer
A, C, F, length 10

More from Shortest path

The whole lesson: Shortest path →