Skip to main content

Minimum spanning trees and connector problems in WACE Mathematics Applications Unit 4

Syllabus dot point

“Solve connector problems by finding a minimum spanning tree using Prim's algorithm and interpret its total weight.”

WACEMathematics ApplicationsUnit 48 min read

Quick answer

A connector problem asks for the cheapest way to link every site so all are connected, directly or indirectly. The answer is a minimum spanning tree: a set of edges connecting all nn vertices with no cycles, using exactly n−1n - 1 edges, of least total weight. Prim's algorithm builds it by repeatedly adding the cheapest edge that reaches a vertex not yet in the tree. Its total weight is the least connection cost.

Jump to a section
  1. What this dot point is asking
  2. Connector problems
  3. Prim's algorithm
  4. Kruskal's algorithm as an alternative
  5. Interpreting the result
  6. Exam-style questions

What this dot point is asking

You must solve connector problems with Prim's algorithm, confirm the tree has n−1n - 1 edges, and interpret the total weight.

Connector problems

A connector problem asks for the least-cost set of links that connects every vertex. The solution is a spanning tree: it spans (reaches) every vertex, and it is a tree (connected, no cycles). The minimum spanning tree has the smallest possible total weight.

Spanning tree

A spanning tree of a connected graph with nn vertices is a subgraph that connects all nn vertices using exactly n−1n - 1 edges and contains no cycles. The minimum spanning tree is the spanning tree of least total weight.

Prim's algorithm

Prim's algorithm grows the tree outward from a starting vertex.

Prim's algorithm
  1. Start at any vertex; it forms the initial tree.
  2. From all edges joining a tree vertex to a vertex not yet in the tree, choose the one of least weight (break ties arbitrarily) and add that edge and vertex.
  3. Repeat until all nn vertices are included; the tree then has n−1n - 1 edges.

The key restriction is that each added edge must reach a new vertex; an edge joining two vertices already in the tree would form a cycle and is never added. (Kruskal's algorithm, which adds the globally cheapest cycle-free edge regardless of connection, gives the same minimum spanning tree.)

Always n minus 1 edges, no cycles

A minimum spanning tree of nn vertices has exactly n−1n - 1 edges and never contains a cycle. If your tree has a loop or the wrong number of edges, you have made an error.

Worked example

Building a minimum spanning tree with Prim's

Five sensors must be networked. Link costs are AB=4AB = 4, AC=6AC = 6, BC=3BC = 3, BD=8BD = 8, CD=5CD = 5, CE=7CE = 7, DE=4DE = 4. Start at AA.

Step 1: Start the tree at vertex A.

Prim's algorithm begins by placing the starting vertex alone in the tree. The tree is {A}\{A\}. The only edges available are those leaving AA: AB=4AB = 4 and AC=6AC = 6. We pick the cheapest, AB=4AB = 4, because Prim's always adds the least-weight edge that reaches a vertex not yet in the tree. Add BB.

Step 2: Extend to vertex C using the cheapest available edge.

The tree is now {A,B}\{A, B\}. We list all edges from tree vertices to non-tree vertices: AC=6AC = 6, BC=3BC = 3, BD=8BD = 8. We consider edges from both AA and BB, because any tree vertex can extend the tree. The cheapest is BC=3BC = 3, so we add edge BCBC and vertex CC.

Step 3: Extend to vertex D.

The tree is {A,B,C}\{A, B, C\}. Edges to non-tree vertices are BD=8BD = 8, CD=5CD = 5, CE=7CE = 7. The cheapest available edge is CD=5CD = 5, so we add edge CDCD and vertex DD.

Step 4: Extend to vertex E to complete the tree.

The tree is {A,B,C,D}\{A, B, C, D\}. The remaining non-tree vertex is EE. Edges that reach EE are CE=7CE = 7 and DE=4DE = 4. We choose DE=4DE = 4 as it is cheaper, add edge DEDE, and include EE in the tree. All five vertices are now connected.

Step 5: Record the tree and compute its total weight.

The spanning tree uses edges AB(4)AB(4), BC(3)BC(3), CD(5)CD(5), DE(4)DE(4). This is 44 edges for 55 vertices, satisfying the n−1=4n - 1 = 4 condition and confirming no cycle exists. The total weight is 4+3+5+4=164 + 3 + 5 + 4 = 16. The cheapest network connecting all five sensors costs 1616.

Kruskal's algorithm as an alternative

Kruskal's algorithm builds the same minimum spanning tree but works globally rather than growing from one vertex. List all edges in order of increasing weight, then add the cheapest edge that does not form a cycle, regardless of where it is in the network, until n−1n - 1 edges have been added. It is often quicker to apply on paper because you sort the edges once and work down the list, skipping any edge that would close a loop. Either algorithm gives the same minimum total weight; choose whichever is faster for the given network.

Interpreting the result

The total weight of the minimum spanning tree is the minimum total cost (length, dollars, cable) to connect every site. It is not the shortest route between two points; a connector problem is about linking everything, not travelling between two named vertices. Read the wording carefully: "connect all", "link every", "least cabling" signal a spanning tree.

In context, the tree's edges are the links that should actually be built, and its total weight is the figure you report (for example, "the cheapest network connecting all six towns uses these five roads and costs $30 000\$30\,000"). If a question asks whether a particular link is in the minimum spanning tree, run the algorithm and check; a link can be the cheapest single edge yet still be excluded if adding it would create a cycle with cheaper alternatives.

Common errors
Confusing the spanning tree with a shortest path
A spanning tree connects all vertices; a shortest path links two named vertices.
Adding an edge that forms a cycle
Each edge in Prim's must reach a vertex not yet in the tree.
Wrong number of edges
A minimum spanning tree of nn vertices has exactly n−1n - 1 edges; more means a cycle, fewer means it is not connected.
Choosing the cheapest overall edge regardless of reach (in Prim's)
Prim's only considers edges that extend the current tree to a new vertex.

Exam-style questions

Questions in the style of SCSA exam questions on this dot point, each with a worked answer. They are written by ExamExplained unless tagged "Past paper"; the year shows the paper a question is modelled on.

WACE 2022-style7 marks
Six towns are to be joined by fibre cable. The possible links (cost in $\$thousands) are AB=7AB=7, AC=5AC=5, BC=8BC=8, BD=9BD=9, CD=7CD=7, CE=5CE=5, DE=15DE=15, DF=6DF=6, EF=8EF=8. (a) Use Prim's algorithm starting at AA to find the minimum spanning tree. (b) State its total cost and the number of edges.
Show worked answer →

Prim's adds the cheapest edge that reaches a new vertex.

Start at AA. Cheapest from AA: AC=5AC = 5, add CC. Cheapest from {A,C}\{A,C\}: CE=5CE = 5, add EE. Cheapest reaching a new vertex from {A,C,E}\{A,C,E\}: AB=7AB = 7 (or CD=7CD = 7); take AB=7AB = 7, add BB. Cheapest reaching new: CD=7CD = 7, add DD. Cheapest reaching FF: DF=6DF = 6, add FF. (5 marks)

Edges: ACAC, CECE, ABAB, CDCD, DFDF, that is 55 edges for 66 towns (n−1=5n-1 = 5). Total cost =5+5+7+7+6=30= 5 + 5 + 7 + 7 + 6 = 30, that is $30 000\$30\,000. (2 marks)

Markers reward growing from AA by cheapest new-vertex edges, exactly 55 edges, and total $30 000\$30\,000.

WACE 2024-style4 marks
Explain the difference between a minimum spanning tree and a shortest path, and state how many edges a minimum spanning tree of nn vertices contains.
Show worked answer →

One connects everything; the other links two points.

A minimum spanning tree connects all vertices together at the least total weight with no cycles; it is about the whole network. A shortest path is the route of least total weight between two specific vertices only. (2 marks)

A minimum spanning tree of nn vertices has exactly n−1n - 1 edges. (2 marks)

Markers reward the connect-everything versus single-journey distinction and the n−1n - 1 edge count.

Practise this

Sources & how we know this

ExamExplained