Leaving Certificate Applied Mathematics2.6 Minimum spanning trees: Kruskal's algorithm

All books

2.6 Minimum spanning trees: Kruskal's algorithm — Practise with help

Warm-up: remember

  1. A connected network has 8 vertices. How many edges has every spanning tree of it?
  2. How many edges are there in the complete network on 5 vertices?
Answers and feedback
  1. 8−1=78 - 1 = 7 edges.
  2. 5×4/2=105 \times 4 / 2 = 10 edges.

Practise with help

1. List these edge weights in the order Kruskal's algorithm considers them: 7,2,5,2,9,17, 2, 5, 2, 9, 1.

Hint

Ascending order.

Next step

The smallest is 1, then two 2s.

Full working 1,  2,  2,  5,  7,  91,\; 2,\; 2,\; 5,\; 7,\; 9

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 PQ=3PQ = 3, PR=6PR = 6, QR=4QR = 4. 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: PQ=3PQ = 3, QR=4QR = 4, PR=6PR = 6.

Full working

Take PQ=3PQ = 3. Then take QR=4QR = 4: it joins RR, a new vertex. The tree is {PQ,QR}\{PQ, QR\} with total 3+4=73 + 4 = 7.

The third edge PR=6PR = 6 is not needed — with 3 vertices the tree needs only 2 edges, and PRPR would close the triangle.

3. A network has 5 vertices and edges AB=1AB = 1, BC=2BC = 2, CD=3CD = 3, DE=4DE = 4, EA=5EA = 5, AC=6AC = 6. 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: AB=1AB = 1, BC=2BC = 2, CD=3CD = 3, DE=4DE = 4, EA=5EA = 5, AC=6AC = 6.

Full working
Edge Weight Add? Why
ABAB 1 yes first edge
BCBC 2 yes new vertex CC
CDCD 3 yes new vertex DD
DEDE 4 yes new vertex EE — four edges chosen, stop

The tree is {AB,BC,CD,DE}\{AB, BC, CD, DE\} with total 1+2+3+4=101 + 2 + 3 + 4 = 10.

EA=5EA = 5 would have closed the cycle A−B−C−D−E−AA-B-C-D-E-A, and AC=6AC = 6 would have closed A−B−C−AA-B-C-A; neither is needed. This network is a pentagon with a diagonal ACAC; the tree is four of its five sides.

4. In that last question, a student adds EA=5EA = 5 before DE=4DE = 4 because they sorted carelessly. What happens, and does the total change?

Hint

Try it: take AB,BC,CD,EAAB, BC, CD, EA — 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

AB,BC,CD,EAAB, BC, CD, EA reaches every vertex and has no cycle, so it is a spanning tree, and the algorithm stops after 4 edges. Its total is 1+2+3+5=111 + 2 + 3 + 5 = 11.

The correct answer was 10. So the total does change: adding EA=5EA = 5 instead of DE=4DE = 4 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 AB=2AB = 2, BC=2BC = 2, CD=2CD = 2, DA=2DA = 2, AC=3AC = 3. 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: AB=2AB = 2, BC=2BC = 2, CD=2CD = 2, DA=2DA = 2, AC=3AC = 3.

Take ABAB, BCBC, CDCD — three edges, all weight 2, reaching all four vertices. Total =6= 6.

But taking ABAB, BCBC, DADA also gives a tree of total 6, and so does ABAB, CDCD, DADA (and others). The minimum weight is unique — 6 — but the tree is not. Any three of the four sides works; the diagonal ACAC 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 n−1n - 1 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 n−1n - 1 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 nn separate vertices and joining two pieces with every edge added, after kk edges there are n−kn - k 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 k=n−1k = n - 1.

So the algorithm adds exactly n−1n - 1 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 n−1=5n - 1 = 5 edges.

Full working

It considers at most 11 edges — each one once, in ascending order. It chooses exactly 6−1=56 - 1 = 5 of them.

In the worst case it rejects 6 edges before reaching 5 chosen. The number of rejections is 11−5=611 - 5 = 6, 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 n−1=1n - 1 = 1 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, n−1=1n - 1 = 1, 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.

Settings

Colour scheme

Light or dark pages. Your colour and layout stay the same.

Colour

The paper, ink and lettering. Your layout stays the same.

Quiet colours
Bold colours
Layout

How pages are arranged. Your colours stay the same.

Reading offline

Keep this book on this device and read it offline.