Steply

Shortest path from A to E: AB 5, AC 3, BD 2, CD 6, BC 1, DE 4, CE 9

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 5, AC 3, BD 2, CD 6, BC 1, DE 4, CE 9

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 = 3 + 9 = 12 ✗

3 Round 1

The smallest open number is A: 0.

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

B: 0 plus 5 is 5.

C: 0 plus 3 is 3.

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

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

0
5A
3A
∞
∞

4 Round 2

The smallest open number is C: 3.

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

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

Change it.

D: 3 plus 6 is 9.

E: 3 plus 9 is 12.

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

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

–
4C
3A
9C
12C

5 Round 3

The smallest open number is B: 4.

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

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

Change it.

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

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

–
4C
–
6B
12C

6 Round 4

The smallest open number is D: 6.

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

E: 6 plus 4 is 10, less than 12.

Change it.

from D: E: 6 + 4 = 10 < 12

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

–
–
–
6B
10D

7 Round 5

The smallest open number is E: 10.

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

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

That is the route.

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

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

9 Check

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

Right!

3 + 1 + 2 + 4 = 10

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

Right!

fewest edges A, C, E: 3 + 9 = 12 > 10

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, C, B, D, E: length 10

Your turn

Try this one yourself, then check:

from A to E: AB 6, AC 3, BD 2, CD 7, BC 2, DE 5, CE 8
Show the answer
A, C, E, length 11

More from Shortest path

The whole lesson: Shortest path →