Te Kete Ipurangi Navigation:

Te Kete Ipurangi

Te Kete Ipurangi user options:

Senior Secondary navigation


How to find a minimum spanning tree

Definitions | Kruskal’s algorithm | Spanning tree example



  • A tree is a connected graph without any cycles.
  • It can also be defined as a connected graph with n vertices and n-1 edges.

Trees are interesting as probably the simplest kind of non-trivial graphs. They have many practical uses, for example, chemistry (showing the structure of hydrocarbons), electrical circuits, computer science, decision making (showing choices), family trees, and mind maps. In a tree, there is a unique path from any vertex to another vertex.



Graph B is a tree. Graph A is not a tree because there is a cycle BCD.

Spanning trees

A spanning tree for a graph, G, is a tree with the same vertices as G and edges that are a subset of the edges in G, that is, it has some of the edges in G but not more.

Spanning trees.

Spanning trees

  • Graph H is not a spanning tree of graph A (above), because vertex D is not connected to the rest of the graph, and so it is not a tree.
  • Graph I is a spanning tree of Graph A because it has some of the edges in Graph A, all the same vertices, and it is a tree.
  • Graph J is not a spanning tree of Graph A because, although it has the same vertices and is a tree, it has the edge AC which was not in the original graph.

It is usually possible to draw more than one spanning tree for a graph.

Minimum spanning trees

If a graph has weights (for example, distance or cost) associated with the edges, then the weight of the graph is the sum of the weights of all its edges. A minimum spanning tree is the spanning tree with minimum weight.

A common problem, in many contexts, is to find a minimum spanning tree, for example, connecting a series of computers together with cabling or a series of villages together with telephone lines.

It is possible to find a minimum spanning tree by trial and error, but it can be time consuming and, if the graph is non trivial, can lead to errors.

Kruskal’s algorithm provides a logical sequence of steps to solve this type of problem. Using Kruskal’s algorithm allows you to show your thinking as you solve the problem. It can also be adapted and written as a computer programme to solve problems for large and complex graphs.

Kruskal’s algorithm

  1. List the edges in order from smallest to largest weight.
  2. Choose the edge with the smallest weight.
  3. Select the next smallest edge that does not complete a cycle.
  4. Repeat step 3 until all vertices are connected.

It is useful to remember that, if there are n vertices in the graph, then there will be n-1 edges in the minimum spanning tree. There will often be more than one possible minimum spanning tree.

Minimum spanning tree example

Telconz is rolling out a fast broadband programme and has to lay fibre cables to collect the isolated farms at the vertices in the following graph.

The distance (weights) on the edges are the length of cabling required to connect each town.

  • What is the minimum spanning tree for this problem?
  • What is the minimum length of cabling required to connect all the farms?
Spanning tree example.

Spanning tree example

List the edges in ascending order of weights, or length in this case:

ED = 2

AB = 3

CD = 4

AE = 4

CD = 4

BC = 5

EF = 5

CF = 6

AF = 7

BF = 8

DF = 8

Spanning trees - part1.

Spanning trees - part1

Spanning trees - part2.

Spanning trees - part2

Spanning trees - part3.

Spanning trees - part3


In this case, we have a unique minimum spanning tree.

If the length of BC was 4km, then the minimum spanning tree would still have length 18 km but would not be unique as any two of the edges AE, CD, and BC could have been chosen. The ones used simply depends on the order that the edges were written in the initial list.

< back to AO M7-5

Last updated May 1, 2012