Steply

Shortest path from A to E: AB 1, AC 7, BC 5, BD 2, CD 1, CE 3, DE 8

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 1, AC 7, BC 5, BD 2, CD 1, CE 3, DE 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, C, E = 7 + 3 = 10 ✗

3 Round 1

The smallest open number is A: 0.

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

B: 0 plus 1 is 1.

C: 0 plus 7 is 7.

from A: B: 0 + 1 = 1, C: 0 + 7 = 7

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

0
1A
7A
∞
∞

4 Round 2

The smallest open number is B: 1.

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

C: 1 plus 5 is 6, less than 7.

Change it.

D: 1 plus 2 is 3.

from B: C: 1 + 5 = 6 < 7, D: 1 + 2 = 3

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

–
1A
6B
3B
∞

5 Round 3

The smallest open number is D: 3.

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

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

Change it.

E: 3 plus 8 is 11.

from D: C: 3 + 1 = 4 < 6, E: 3 + 8 = 11

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

–
–
4D
3B
11D

6 Round 4

The smallest open number is C: 4.

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

E: 4 plus 3 is 7, less than 11.

Change it.

from C: E: 4 + 3 = 7 < 11

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

–
–
4D
–
7C

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

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

That is the route.

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

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

9 Check

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

Right!

1 + 2 + 1 + 3 = 7

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

Right!

fewest edges A, C, E: 7 + 3 = 10 > 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, D, C, E: length 7

Your turn

Try this one yourself, then check:

from A to E: AB 1, AC 7, BC 5, BD 3, CD 1, CE 3, DE 9
Show the answer
A, B, D, C, E, length 8

More from Shortest path

The whole lesson: Shortest path →