Steply

Shortest path from B to E: AB 2, BC 3, CD 1, BD 5, DE 2, CE 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 B to E.

from B to E: AB 2, BC 3, CD 1, BD 5, DE 2, CE 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 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, C, E = 3 + 6 = 9 ✗

3 Round 1

The smallest open number is B: 0.

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

A: 0 plus 2 is 2.

C: 0 plus 3 is 3.

D: 0 plus 5 is 5.

from B: A: 0 + 2 = 2, C: 0 + 3 = 3, D: 0 + 5 = 5

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

2B
0
3B
5B
∞

4 Round 2

The smallest open number is A: 2.

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

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

2B
–
3B
5B
∞

5 Round 3

The smallest open number is C: 3.

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

D: 3 plus 1 is 4, less than 5.

Change it.

E: 3 plus 6 is 9.

from C: D: 3 + 1 = 4 < 5, E: 3 + 6 = 9

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

–
–
3B
4C
9C

6 Round 4

The smallest open number is D: 4.

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

E: 4 plus 2 is 6, less than 9.

Change it.

from D: E: 4 + 2 = 6 < 9

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

–
–
–
4C
6D

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 D, D from C, C from B.

E from D, D from C, C from B

That is the route.

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

= B, C, D, E: length 6

9 Check

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

Right!

3 + 1 + 2 = 6

The route with the fewest edges, B, C, E, is 9: longer.

Right!

fewest edges B, C, E: 3 + 6 = 9 > 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: round 5.

Then: the route back.

Last: check.

Answer
= B, C, D, E: length 6

Your turn

Try this one yourself, then check:

from B to E: AB 1, BC 4, CD 2, BD 5, DE 3, CE 5
Show the answer
B, D, E, length 8

More from Shortest path

The whole lesson: Shortest path →