13.7: Spanning Trees
- Last updated
- Aug 12, 2022
- Save as PDF
- Page ID
- 109946
( \newcommand{\kernel}{\mathrm{null}\,}\)
A company requires reliable internet and phone connectivity between their five offices (named A, B, C, D, and E for simplicity) in New York, so they decide to lease dedicated lines from the phone company. The phone company will charge for each link made. The costs, in thousands of dollars per year, are shown in the graph.
In this case, we don’t need to find a circuit, or even a specific path; all we need to do is make sure we can make a call from any office to any other. In other words, we need to be sure there is a path from any vertex to any other vertex.
Spanning Tree
A spanning tree is a connected graph using all vertices in which there are no circuits.
In other words, there is a path from any vertex to any other vertex, but no circuits.
Some examples of spanning trees are shown below. Notice there are no circuits in the trees, and it is fine to have vertices with degree higher than two.
Usually we have a starting graph to work from, like in the phone example above. In this case, we form our spanning tree by finding a subgraph – a new graph formed using all the vertices but only some of the edges from the original graph. No edges will be created where they didn’t already exist.
Of course, any random spanning tree isn’t really what we want. We want the minimum cost spanning tree (MCST).
Minimum Cost Spanning Tree (MCST)
The minimum cost spanning tree is the spanning tree with the smallest total edge weight.
A nearest neighbor style approach doesn’t make as much sense here since we don’t need a circuit, so instead we will take an approach similar to sorted edges.
Kruskal’s Algorithm
- Select the cheapest unused edge in the graph.
- Repeat step 1, adding the cheapest unused edge, unless:
- adding the edge would create a circuit
- Repeat until a spanning tree is formed
Example 22
Using our phone line graph from above, begin adding edges:
AB$4OKAE$5OKBE $6reject-closes circuit ABEADC$7OKAC$8OK
At this point we stop – every vertex is now connected, so we have formed a spanning tree with cost $24 thousand a year.
Remarkably, Kruskal’s algorithm is both optimal and efficient; we are guaranteed to always produce the optimal MCST.
Example 23
The power company needs to lay updated distribution lines connecting the ten Oregon cities below to the power grid. How can they minimize the amount of new line to lay?
Ashland Astoria Bend Corvallis Crater Lake Eugene Newport Portland Salem Seaside Ashland _374200223108178252285240356 Astoria 374_2551664331991359513617 Bend 200255_128277128180160131247 Corvallis 223166128_43047528440155 Crater Lake 108433277430_453478344389423 Eugene 17819912847453_9111064181 Newport 2521351805247891_11483117 Portland 2859516084344110114_4778 Salem 24013613140389648347_118 Seaside 3561724715542318111778118_
Solution
Using Kruskal’s algorithm, we add edges from cheapest to most expensive, rejecting any that close a circuit. We stop when the graph is connected.
Seaside to Astoria17 milesCorvallis to Salem40 milesPortland to Salem47 milesCorvallis to Eugene47 milesCorvallis to Newport52 milesSalem to Eugenereject – closes circuitPortland to Seaside78 miles
The graph up to this point is shown to the right.
Continuing,
Newport to SalemrejectCorvallis to PortlandrejectEugene to NewportrejectPortland to AstoriarejectAshland to Crater Lk108 milesEugene to PortlandrejectNewport to PortlandrejectNewport to SeasiderejectSalem to SeasiderejectBend to Eugene128 milesBend to SalemrejectAstoria to NewportrejectSalem to AstoriarejectCorvallis to SeasiderejectPortland to BendrejectAstoria to CorvallisrejectEugene to Ashland178 miles
This connects the graph. The total length of cable to lay would be 695 miles.
Try it Now 7
Find a minimum cost spanning tree on the graph below using Kruskal’s algorithm.
- Answer
-
AB: Add, cost 11
BG: Add, cost 13
AE: Add, cost 14
AG: Skip, would create circuit ABGA
EF: Add, cost 16
EC: Add, cost 17
This completes the spanning tree