Steply

Shortest path from A to E: AB 6, AC 2, CD 3, BD 1, BE 2, DE 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 A to E.

from A to E: AB 6, AC 2, CD 3, BD 1, BE 2, DE 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 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!

A number can still go down later.

It is final only when it is the smallest open one and gets its ring.

Careful: a number is final only when it is ringed

3 Round 1

The smallest open number is A: 0.

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

B: 0 plus 6 is 6.

C: 0 plus 2 is 2.

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

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

0
6A
2A
∞
∞

4 Round 2

The smallest open number is C: 2.

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

D: 2 plus 3 is 5.

from C: D: 2 + 3 = 5

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

–
6A
2A
5C
∞

5 Round 3

The smallest open number is D: 5.

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

B: 5 plus 1 is 6, not less than 6.

Keep 6.

E: 5 plus 6 is 11.

from D: B: 5 + 1 = 6 ≥ 6, E: 5 + 6 = 11

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

–
6A
–
5C
11D

6 Round 4

The smallest open number is B: 6.

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

E: 6 plus 2 is 8, less than 11.

Change it.

from B: E: 6 + 2 = 8 < 11

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

–
6A
–
–
8B

7 Round 5

The smallest open number is E: 8.

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

8 The route back

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

E from B, B from A

That is the route.

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

= A, B, E: length 8

9 Check

Add the lengths along the route: 6 + 2 = 8.

Right!

6 + 2 = 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: round 5.

Then: the route back.

Last: check.

Answer
= A, B, E: length 8

Your turn

Try this one yourself, then check:

from A to E: AB 6, AC 3, CD 2, BD 1, BE 3, DE 7
Show the answer
A, B, E, length 9

More from Shortest path

The whole lesson: Shortest path →