Graphs · Exercise 44 of 100
Kruskal’s minimum spanning tree
A minimum spanning tree connects all vertices of a connected, undirected, weighted graph with the lowest possible total edge cost and no cycle. Kruskal’s algorithm considers edges from cheapest to most expensive and takes an edge only when it joins two previously separate groups.
Try it yourself
Possible cable links have costs AB 1, BC 2, AC 3, CD 5 and BD 8. All links work both ways. What total cost does Kruskal’s algorithm pay to connect the four sites?
One-step hint
Examine cables from cheapest to priciest. Before adding a cost to your total, check whether the cable's endpoints are already connected.
Worked solution
- Take AB and BC. Skip AC because A and C are already connected through B.
- Take CD to bring in the last site D, giving a total cost of 1 + 2 + 5 = 8.