Spanning Trees and Route Problems

Stage 23 of 23 Strand 4 of 5 6 lessons

6 illustrated lessons, each teaching the why before the how.

Start with Kruskal’s Algorithm for a Spanning Tree in the app →
Revise Spanning Trees and Route Problems with flashcards →

Jump to a lesson

Kruskal’s Algorithm for a Spanning Tree

Cheapest edge first, unless it closes a cycle.

Kruskal takes the cheapest edge that closes no cycle, until every vertex is joined

Read the full lesson →

42563789ABCDE

Join every town at the lowest total cost. The answer is a minimum spanning tree.

42563789ABCDE

Sort the edges by weight and take the cheapest: A to C, weight 2.

42563789ABCDE

Next cheapest is C to E, weight 3. It reaches a new town, so keep it.

42563789ABCDE

A to B, weight 4, brings in B. Keep that one too.

42563789ABCDE

B to C, weight 5, would close the cycle A-B-C. Reject it and move on.

42563789ABCDE

B to D, weight 6, brings in the last town, so the tree is finished.

4263ABCDE

Five towns need four edges, and the total weight is 2 + 3 + 4 + 6 = 15.

Now you

5723121168ABCDE

Which edge does Kruskal add last?

139514786ABCDE

How many edges does the minimum spanning tree of these five towns have?

Prim’s Algorithm and the Matrix Method

One tree, grown outward, on paper or in a table.

Prim grows one tree outward, always taking the cheapest edge that reaches a new vertex

Read the full lesson →

42563789ABCDE

Start anywhere. Take A, and look only at the edges leaving the tree so far.

42563789ABCDE

The cheapest edge leaving A is A to C, weight 2, so C joins the tree.

42563789ABCDE

Now scan every edge leaving A or C. The cheapest is C to E, weight 3.

42563789ABCDE

Of the edges leaving the tree now, A to B at 4 is cheapest, so B joins.

42563789ABCDE

Then B to D at 6, and every town is in. It is the same tree Kruskal found, with the same total of 15.

ABCDEA—42——B4—569C25—83D—68—7E—937—

The matrix method does the same work. Cross out column A, then scan row A.

ABCDEA—42——B4—569C25—83D—68—7E—937—

The smallest entry in row A is 2, in column C. Circle it, and C joins the tree.

ABCDEA—42——B4—569C25—83D—68—7E—937—

Cross out column C, scan rows A and C together, and the smallest left is 3.

Now you

1483762411ABCDE

Prim starts at A. Which edge does it take first?

251012111396ABCDE

Prim and Kruskal are run on the same network. What do they produce?

The Chinese Postman Problem

Repeat just enough to make the degrees even.

The shortest closed route over every edge repeats just enough of them to make all degrees even

Read the full lesson →

53462A2B3C3D2

A postman walks every street and comes home. The streets total 5 + 3 + 4 + 6 + 2 = 20.

53462AB3C3D

B and C have odd degree, so no closed trail can use every street exactly once.

53462ABCD

Some street must be walked twice, so find the cheapest route joining the two odd vertices.

53462ABCD

B to C direct costs 4, and going around by D costs 6 + 2 = 8, so take the direct street.

534462A2B4C4D2

Walk that street twice and every degree is even, so a closed trail now exists.

53462ABCD

The shortest closed route is every street once, plus that repeat: 20 + 4 = 24.

Now you

86524ABCD

What is the length of the shortest closed route using every street?

965410A2B3C3D2

Which vertices of this network have odd degree?

The Traveling Salesman Problem

The cheapest cycle through every town.

The traveling salesman problem asks for the cheapest cycle that visits every vertex once

Read the full lesson →

564798ABCD

Visit every town once and come home, as cheaply as possible.

564798ABCD

Any answer is a Hamiltonian cycle. This one costs 5 + 6 + 4 + 7 = 22.

564798ABCD

A different order costs 5 + 8 + 4 + 9 = 26, so the problem is choosing the order of the towns.

564798ABCD

Four towns give only 3 cycles, but ten towns give over 180 thousand, so listing them fails.

56478ABCD

A real network has missing roads: there is no road at all from A to C here.

ABCDA—5117B5—68C116—4D784—

Replace each pair by its shortest route: A to C becomes 11, going around through B.

Now you

73212410ABCD

What does the cycle A-B-C-D-A cost?

ABCDE

How many different cycles visit all 5 towns?

The Nearest-Neighbor Upper Bound

A tour you can walk is a ceiling on the best.

Always moving to the nearest unvisited vertex gives a tour, whose length is an upper bound

Read the full lesson →

38694752610ABCDE

Start at A and always move to the nearest town not yet visited.

38694752610ABCDE

From A the nearest is B, at 3.

38694752610ABCDE

From B the nearest town not yet visited is C, at 4.

38694752610ABCDE

From C the nearest town not yet visited is D, at 2.

38694752610ABCDE

Only E is left, so the tour has to take it, at a cost of 10.

394210ABCDE

Home to A costs 9, so the tour is 3 + 4 + 2 + 10 + 9 = 28.

38694752610ABCDE

Another tour costs only 22, so 28 is an upper bound and not the cheapest tour.

Now you

38694752610ABCDE

A nearest-neighbor tour costs 22. What does that tell you?

38694752610ABCDE

The tour starts at B. Which town comes next?

The Deleted-Vertex Lower Bound

Take one town out, span the rest, put it back.

Deleting a vertex, spanning the rest, and adding back its two cheapest edges gives a lower bound

Read the full lesson →

38694752610ABCDE

Delete one town, say A, together with every road that touches it.

4752610BCDE

What is left is a smaller network on B, C, D and E.

4752610BCDE

Its minimum spanning tree is C-D at 2, B-C at 4 and B-E at 5: total 11.

38694752610ABCDE

Put A back with its two cheapest roads only: 3 and 6.

38694752610ABCDE

Together that is 11 + 3 + 6 = 20.

38694752610ABCDE

Every tour uses two roads at A, and its other roads join B, C, D and E, which costs at least 11, so no tour can cost under 20.

38694752610ABCDE

With the tour of 28 found before, the cheapest tour lies between 20 and 28.

Now you

8692610ACDE

Vertex B is deleted. What is the weight of the minimum spanning tree of the rest?

38694752610ABCDE

What do the two cheapest roads at C come to?

Continue your journey in the app — save your progress