2.6 Minimum spanning trees: Kruskal's algorithm — Practise with help
Warm-up: remember
- A connected network has 8 vertices. How many edges has every spanning tree of it?
- How many edges are there in the complete network on 5 vertices?
Answers and feedback
- edges.
- edges.
Practise with help
1. List these edge weights in the order Kruskal's algorithm considers them: .
Hint
Ascending order.
Next step
The smallest is 1, then two 2s.
Full working
The two 2s may be taken in either order — the total weight of the tree will be the same either way.
2. A network has edges , , . Find the minimum spanning tree and its total weight.
Hint
Three vertices, so the tree needs 2 edges. Take the two cheapest that do not form a cycle.
Next step
Sorted: , , .
Full working
Take . Then take : it joins , a new vertex. The tree is with total .
The third edge is not needed — with 3 vertices the tree needs only 2 edges, and would close the triangle.
3. A network has 5 vertices and edges , , , , , . Find the minimum spanning tree and its total weight.
Hint
Five vertices, so 4 edges are needed. Work down the sorted list.
Next step
Sorted: , , , , , .
Full working
| Edge | Weight | Add? | Why |
|---|---|---|---|
| 1 | yes | first edge | |
| 2 | yes | new vertex | |
| 3 | yes | new vertex | |
| 4 | yes | new vertex — four edges chosen, stop |
The tree is with total .
would have closed the cycle , and would have closed ; neither is needed. This network is a pentagon with a diagonal ; the tree is four of its five sides.
4. In that last question, a student adds before because they sorted carelessly. What happens, and does the total change?
Hint
Try it: take — that is already 4 edges.
Next step
Four edges are chosen, and every vertex is reached, so the algorithm stops. Is the total the same as before?
Full working
reaches every vertex and has no cycle, so it is a spanning tree, and the algorithm stops after 4 edges. Its total is .
The correct answer was 10. So the total does change: adding instead of costs 1 more. That is what the sorting is for — if the edges are not considered in ascending order, the algorithm still returns a spanning tree, but no longer the minimum one.
5. A network has edges , , , , . Find the minimum spanning tree and say whether it is unique.
Hint
The four sides of the square all weigh 2, and the diagonal weighs 3.
Next step
Four vertices, so 3 edges. Sorted: the four 2s, then the 3.
Full working
Sorted: , , , , .
Take , , — three edges, all weight 2, reaching all four vertices. Total .
But taking , , also gives a tree of total 6, and so does , , (and others). The minimum weight is unique — 6 — but the tree is not. Any three of the four sides works; the diagonal is never used, because it weighs more.
When weights are tied, say so: "a minimum spanning tree" rather than "the minimum spanning tree".
6. Explain why Kruskal's algorithm must eventually choose exactly edges.
Hint
It never closes a cycle, and it keeps going until it cannot add more.
Next step
What would it mean if it stopped with fewer than edges, and the network is connected?
Full working
The algorithm never adds an edge that closes a cycle, so the chosen edges always form a forest — a set of trees. It adds an edge whenever the two ends are in different pieces, which is exactly when the edge joins two pieces into one.
Starting from separate vertices and joining two pieces with every edge added, after edges there are pieces. When there is only one piece, every vertex is connected and no further edge can be added without closing a cycle. That happens when .
So the algorithm adds exactly edges, and the result is a spanning tree.
A question from Section 2.5
7. A network has 6 vertices and 11 edges. How many edges must Kruskal's algorithm consider at most, and how many does it choose?
Hint
It looks at each edge once, in order.
Next step
It stops when it has edges.
Full working
It considers at most 11 edges — each one once, in ascending order. It chooses exactly of them.
In the worst case it rejects 6 edges before reaching 5 chosen. The number of rejections is , which is exactly the number of edges that had to be removed to turn the network into a spanning tree in Section 2.5.
8. A network has two vertices joined by an edge of weight 10, and no other edges. What is its minimum spanning tree, and what is its total weight?
Hint
Two vertices, so edge.
Next step
There is only one edge.
Full working
The only spanning tree is the single edge itself, with total weight 10.
This is worth checking against the algorithm: there is one edge, , so the algorithm takes it and stops. The minimum spanning tree of a network with two vertices is always just the edge between them, however heavy it is — there is no choice to make.