Steply

Shortest path from C to A: AB 3, BC 5, AC 10, BD 2, CD 4, AD 6

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

Step by step

The question

Question: find the shortest path from C to A.

from C to A: AB 3, BC 5, AC 10, BD 2, CD 4, AD 6

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 C so far, and, small, the vertex we came from.

∞
∞

C 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 C, A = 10 = 10 ✗

3 Round 1

The smallest open number is C: 0.

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

A: 0 plus 10 is 10.

B: 0 plus 5 is 5.

D: 0 plus 4 is 4.

from C: A: 0 + 10 = 10, B: 0 + 5 = 5, D: 0 + 4 = 4

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

10C
5C
0
4C

4 Round 2

The smallest open number is D: 4.

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

A: 4 plus 6 is 10, not less than 10.

Keep 10.

B: 4 plus 2 is 6, not less than 5.

Keep 5.

from D: A: 4 + 6 = 10 ≥ 10, B: 4 + 2 = 6 ≥ 5

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

10C
5C
–
4C

5 Round 3

The smallest open number is B: 5.

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

A: 5 plus 3 is 8, less than 10.

Change it.

from B: A: 5 + 3 = 8 < 10

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

8B
5C
–
–

6 Round 4

The smallest open number is A: 8.

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

7 The route back

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

A from B, B from C

That is the route.

The shortest path is C, B, A, length 8.

= C, B, A: length 8

8 Check

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

Right!

5 + 3 = 8

The route with the fewest edges, C, A, is 10: longer.

Right!

fewest edges C, A: 10 = 10 > 8

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
= C, B, A: length 8

Your turn

Try this one yourself, then check:

from C to A: AB 3, BC 5, AC 11, BD 1, CD 5, AD 6
Show the answer
C, B, A, length 8

More from Shortest path

The whole lesson: Shortest path →