Steply

Shortest path from B to D: AB 4, AD 3, BC 2, CD 6, AC 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 B to D.

from B to D: AB 4, AD 3, BC 2, CD 6, AC 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 B so far, and, small, the vertex we came from.

∞

B 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 B, A, D = 4 + 3 = 7 ✗

3 Round 1

The smallest open number is B: 0.

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

A: 0 plus 4 is 4.

C: 0 plus 2 is 2.

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

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

4B
0
2B
∞

4 Round 2

The smallest open number is C: 2.

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

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

Change it.

D: 2 plus 6 is 8.

from C: A: 2 + 1 = 3 < 4, D: 2 + 6 = 8

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

3C
–
2B
8C

5 Round 3

The smallest open number is A: 3.

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

D: 3 plus 3 is 6, less than 8.

Change it.

from A: D: 3 + 3 = 6 < 8

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

3C
–
–
6A

6 Round 4

The smallest open number is D: 6.

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

7 The route back

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

D from A, A from C, C from B

That is the route.

The shortest path is B, C, A, D, length 6.

= B, C, A, D: length 6

8 Check

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

Right!

2 + 1 + 3 = 6

The route with the fewest edges, B, A, D, is 7: longer.

Right!

fewest edges B, A, D: 4 + 3 = 7 > 6

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

Your turn

Try this one yourself, then check:

from B to D: AB 4, AD 2, BC 1, CD 7, AC 2
Show the answer
B, C, A, D, length 5

More from Shortest path

The whole lesson: Shortest path →