D1 2.1 - Minimum spanning trees

D1 2.1 - Minimum spanning trees

You will find a minimum connector using Kruskal's and Prim's algorithms, show the order of selected arcs, and move between a weighted network and its matrix.

Connecting every node as cheaply as possible

Can a correct minimum-connector algorithm choose an arc of weight 77 before an arc of weight 22? It can. The answer depends on which algorithm you use, because their rules for eligible arcs differ.

You already know

A tree is connected and has no cycles. A tree on nn nodes has n−1n-1 arcs. Arc weights are supplied data; their drawn lengths do not determine their weights.

Imagine installing cables between five buildings. You need every building connected, possibly through others; you do not need a direct cable between every pair. A cycle would provide a redundant connection, so a cheapest connector can be sought among trees.

[DIAGRAM: asset_name: A network and one minimum connector; asset_slug: 9fm0-d1-166-minimum-connector; caption: The blue arcs connect all five nodes without a cycle, with total weight 17.; description: A connected five-node network with weights AB2, AC3, BC4, BD5, CD6, CE7, DE8 and BE9, with AB, AC, BD and CE highlighted as a spanning tree.]
The blue arcs connect all five nodes without a cycle, with total weight 17.

Minimum spanning tree

A spanning tree of a connected undirected graph is a subgraph containing every node and forming a tree. A minimum spanning tree, or minimum connector, has the least total arc weight among all spanning trees of the network.

The minimum is the total weight of the chosen arcs. This is different from finding a shortest path between two specified nodes: a minimum spanning tree need not give the shortest route between every pair.

For positive connection costs, deleting an arc from a cycle preserves connectedness and reduces cost. That explains why redundant cycles are unnecessary. With equal weights there can be several minimum trees, but their minimum total is the same. The algorithms below find one.

Key idea

A minimum spanning tree connects all nodes with no cycle and minimises the sum of the chosen arc weights. It is a network of connections, not necessarily one continuous route.

Check the whole structure rather than only the number of arcs.

Kruskal's algorithm

Kruskal looks at the whole network in increasing weight order. Its selected arcs may initially form separate pieces; rejecting cycles is what keeps those pieces capable of joining into a tree.

Kruskal's algorithm

List the arcs in increasing weight order. Consider each in turn, accepting it unless it creates a cycle with the accepted arcs. Stop when n−1n-1 arcs have been accepted for the nn nodes of the connected network.

Equal-weight arcs may be considered in either order unless a tie rule is specified. We use alphabetical arc order to make the displayed trace reproducible. A rejected arc stays rejected. Check whether its endpoints are already connected by accepted arcs; if so, adding it would create a cycle.

Not in the formula booklet: learn it.

Worked example 1: skipping cheaper arcs that create cycles

Question. Use Kruskal's algorithm on the network with arc weights

AB=2, AC=3, BC=4, BD=5, CD=6, CE=7, DE=8, BE=9AB=2,\ AC=3,\ BC=4,\ BD=5,\ CD=6,\ CE=7,\ DE=8,\ BE=9

List the accepted arcs in order and find the minimum weight.

Plan. Scan the weights in increasing order, record rejections and stop after four accepted arcs.

ArcWeightDecisionReason
ABAB22AcceptFirst connection
ACAC33AcceptJoins CC to the selected part
BCBC44RejectCreates cycle B,A,C,BB,A,C,B
BDBD55AcceptJoins DD
CDCD66RejectC,DC,D are already connected
CECE77AcceptJoins EE; four arcs selected

Why reject BCBC even though it is cheaper than BDBD? It joins nodes already connected through AA, so it would create a cycle rather than connect a new component.

Answer. Accepted order: AB,AC,BD,CEAB,AC,BD,CE. Minimum weight:

2+3+5+7=172+3+5+7=17

Check. All five nodes are connected by four arcs with no cycle. The highlighted tree in the diagram has these arcs.

Worked example 2 changes only CDCD, from weight 66 to weight 55. A tie now gives a genuine choice.

Worked example 2: equal weights

Question. Use Kruskal's algorithm when

AB=2, AC=3, BC=4, BD=5, CD=5, CE=7, DE=8, BE=9AB=2,\ AC=3,\ BC=4,\ BD=5,\ CD=5,\ CE=7,\ DE=8,\ BE=9

Use alphabetical arc order to break ties.

Plan. Retain increasing weight order, placing BDBD before CDCD, and continue checking cycles.

ArcWeightDecisionReason
ABAB22AcceptNo cycle
ACAC33AcceptNo cycle
BCBC44RejectCompletes the triangle
BDBD55AcceptAdds DD
CDCD55RejectIts endpoints are now connected
CECE77AcceptAdds the last node

Why state the tie choice? It explains why BDBD, rather than CDCD, enters this particular tree. If CDCD were considered first, it could be accepted and BDBD rejected instead.

Answer. This trace gives AB,AC,BD,CEAB,AC,BD,CE, of weight 1717. The alternative AB,AC,CD,CEAB,AC,CD,CE is also a minimum tree of weight 1717.

Check. In either tree the two tied arcs contribute exactly one weight of 55; both trees connect all nodes without a cycle.

Here the repeated weights produce two minimum trees. Equal weights do not always produce several minimum trees; it depends on which alternatives can actually be exchanged.

Watch out

Wrong: take the four cheapest arcs regardless of their connections. Right: every accepted arc must avoid a cycle. Show rejected arcs where they explain why a larger weight is selected.

Introduce a second tie in the matched trace.

Prim's algorithm from a specified node

Prim grows one connected tree from its starting node. At each step it considers all arcs from the selected set to an unselected node, not just arcs from the most recently added node.

Prim's algorithm

Start at the specified node. Choose a least-weight arc joining a selected node to an unselected node, add that arc and the new node, and repeat until every node is selected.

An arc with both ends selected is ineligible, even if it is cheap. An arc with neither end selected is also ineligible for now. A tie may be resolved either way unless instructed otherwise. Prim never creates a cycle because each accepted arc adds a new node.

Not in the formula booklet: learn it.

Continue this lesson.

You’re previewing NovaLearn without an account. Create a free account to read the rest.

Create free account