Trees, minimum spanning trees and Prim's algorithm: VCE General Mathematics Unit 4 Networks and decision mathematics
“Identify trees and spanning trees, determine a minimum spanning tree of a weighted connected graph by inspection or by Prim's algorithm (from a network or a table), and use minimum spanning trees to solve minimal connector problems”
A tree is a connected graph with no cycles; with vertices it has exactly edges and its degrees add to . A spanning tree is a tree using every vertex of a graph. The minimum spanning tree has the least total weight. Prim's algorithm: start anywhere, then repeatedly add the cheapest edge that joins the tree to a new vertex, until edges are in. By inspection: add the cheapest edges overall, skipping any that make a cycle. Both give the same minimum weight.
What this dot point is asking
The Study Design's "Trees and minimum connector problems" topic has three parts: "trees and spanning trees", "minimum spanning trees in a weighted connected graph and their determination by inspection or by Prim's algorithm", and "use of minimal spanning trees to solve minimal connector problems". A minimal connector problem asks for the cheapest (or shortest) set of links that joins every location: cabling buildings, piping houses, sealing roads between towns.
You need to:
- recognise a tree and know its properties;
- find a spanning tree of a graph;
- find a minimum spanning tree by inspection or by Prim's algorithm, from a network diagram or a table, and give its weight;
- handle variations: an edge that must be included, an unknown weight, a new edge.
These are usually one-mark multiple-choice questions (2023 Examination 1 Question 35, ; 2025 Examination 1 Question 35, ) or a short part of an Examination 2 networks question.
The answer
Trees
A tree is a connected graph with no cycles. Every tree with vertices has:
- exactly edges;
- exactly one path between any two vertices;
- a sum of degrees of , because every edge adds 2 to the degree sum;
- at least two vertices of degree 1 (if ).
Removing any edge from a tree disconnects it (every edge is a bridge), and adding any edge between two of its vertices creates exactly one cycle. For planar graphs, a tree has one face, so Euler's formula becomes , which checks out.
Spanning trees
A spanning tree of a connected graph is a subgraph that includes every vertex and is a tree. A graph usually has many spanning trees. If the graph has vertices and edges, a spanning tree keeps of them, so edges are removed, each one breaking a cycle without disconnecting anything. When you draw one, use only edges from the original graph (in 2025 Examination 2 Question 15d, succeeded; some lost the mark by adding an edge that was not in the graph).
Minimum spanning trees
In a weighted graph, a minimum spanning tree is a spanning tree with the smallest total weight. It is the answer to every minimal connector problem. There may be more than one minimum spanning tree when some weights are equal, but they all have the same total.
Prim's algorithm
- Start at any vertex. It is the tree so far.
- Look at every edge that joins a vertex in the tree to a vertex not yet in the tree. Add the one with the smallest weight (if there is a tie, either will do).
- Repeat step 2 until all vertices are in, which takes edges.
Because each new edge always goes to a new vertex, Prim's algorithm can never create a cycle. The starting vertex can change the order in which edges are added, but not the total.
In the figure, starting at : ; then from the cheapest is ; then ; then ; then and (tied, either first). Total .
Finding it by inspection
For small networks (and most multiple-choice questions), list the edges from smallest to largest and add them one at a time, skipping any edge that would complete a cycle, until you have edges. This greedy method always gives a minimum spanning tree. It adds edges in a different order from Prim's, so use Prim's whenever a question asks for "the order in which Prim's algorithm adds the edges".
Prim's algorithm from a table
Networks are often given as a table of weights, with a dash for "no direct link". The method is unchanged:
- Circle the starting vertex. Its row lists the edges from it.
- Among the rows of all vertices already chosen, pick the smallest weight leading to a vertex not yet chosen.
- Add that vertex and repeat, ignoring entries between two chosen vertices.
Record each edge as you add it; the list is both your working and the answer.
Forced edges, unknown weights and new edges
- An edge must be included (an existing road, a fixed link): put it in first, then carry on choosing the cheapest edges that avoid cycles. The total can only stay the same or rise.
- An unknown weight is in the tree (2025 Examination 1 Question 35): include first, find the other edges, and write the length as a number plus .
- A new edge is proposed: it enters the tree only if it is lighter than the heaviest edge on the cycle it would create with the tree.
Minimum spanning tree or shortest path?
A minimum spanning tree connects all vertices at least total cost. The route it gives between two particular vertices is often not the shortest route between them. In the figure, the tree route from to is , but the direct path -- is only . "Connect everything" means minimum spanning tree; "quickest way from here to there" means shortest path (Dijkstra's algorithm).
Prim's algorithm on the network in the figure
Find the minimum spanning tree starting from , and check the total.
- Step 1
- Tree . Edges out: , . Add .
- Step 2
- Tree . Edges out: , , , . Add .
- Step 3
- Tree . Edges out: 9, 12, 10, 8, 6, 7. Add .
- Step 4
- Tree . New options from : 5, 9, 11. Add .
- Step 5
- Tree . Options include 7, 7, 8. Add (tie with ).
- Step 6
- Only remains: is cheapest (against 9, 10, 11). Add .
- Answer
- Edges , , , , , : six edges for seven vertices, total , the same as starting from .
From a table, with a forced edge
Road lengths (km) between five towns, dash for no possible road:
| 14 | 9 | 20 | - | ||
| 14 | 12 | - | 8 | ||
| 9 | 12 | 11 | 15 | ||
| 20 | - | 11 | 10 | ||
| - | 8 | 15 | 10 |
Step 1: start at . Row : smallest is .
Step 2: rows and . Candidates to new towns: 14, 20, 12, 11, 15. Add .
Step 3: rows , , . New options from : 10. Smallest overall is . Add .
Step 4: last town . Options 14, 12, 8. Add .
Answer. , , , : minimum length km. If the existing road must be kept, include it first and continue with , , (now would close a cycle): total 47 km, 9 km more.
An unknown weight in the tree
A network has vertices , , , , and edges , , , , , , . The minimum spanning tree includes edge . Find its length in terms of , and the largest possible whole-number value of .
- Step 1: include , then the cheapest edges without cycles
- , (joins to ), then would close the cycle ----, so skip it. would also close a cycle. adds .
- Step 2: total
- Edges , , , : length .
- Step 3: when is really in the tree
- Without , would join by (tree , , , , weight 19). is used only if , that is . Largest whole number: (a tie, where both trees weigh 19).
- Wrong number of edges
- A spanning tree of vertices has exactly edges. Count before you add up.
- Closing a cycle by inspection
- When choosing the cheapest edges overall, check each new edge does not join two vertices already connected.
- Treating inspection order as Prim's order
- If asked for Prim's order, only edges touching the current tree are allowed at each step.
- Reading a table's dash as zero
- A dash means there is no edge.
Using an edge that is not in the graph when drawing a spanning tree.
Confusing a minimum spanning tree with a shortest path. The tree minimises the total of all edges, not the distance between two chosen vertices.
Forgetting a forced edge or in the total. Include it and add its weight.
For multiple-choice minimum spanning tree questions, write first, then list the chosen weights in increasing order and tick them off on the diagram; if you have too many or too few, recheck for cycles. For Prim's questions, write each step as "tree so far: cheapest edge out" so the marker can follow your order. Always give the total with units, and in context say what it means ("the minimum length of cable needed is 38 km").
A tree is a network with no loops, so there is exactly one way between any two points and it always has one fewer link than points. When you need to join every place with the least cable, road or pipe, you want the cheapest tree that reaches everywhere: the minimum spanning tree. Prim's method grows it one step at a time, always adding the cheapest link to a place not yet connected. The result joins everything cheaply, but it is not meant to be the fastest route between any two particular places.
Exam-style questions
Questions in the style of VCAA 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.
2023 VCAA-style1 markA graph has five vertices joined in a single chain by four edges, with no other edges. How many of the following five statements are true? The graph is a tree. The graph is connected. The graph contains a path. The graph contains a cycle. The sum of the degrees of the vertices is eight. A. 1 B. 2 C. 3 D. 4 E. 5
Show worked answer →
- Tree: true. It is connected and has no cycle (5 vertices, edges).
- Connected: true. Every vertex can be reached from every other.
- Contains a path: true. Any route along the chain is a path (no repeated vertices).
- Contains a cycle: false. A tree never contains a cycle.
- Sum of degrees is eight: true. The sum of the degrees is the number of edges .
Four statements are true: option D ( correct; chose C, usually by rejecting "contains a path" or miscounting degrees).
Source: VCAA 2023 General Mathematics Examination 1, Question 33, and the 2023 examination report. (The paper shows the graph as a drawing; it is described in words here.)
2023 VCAA-style1 markA weighted graph has six vertices and seven edges. Labelling the vertices to (the paper leaves them unlabelled), the edges are , , , , , and . The weight of the minimum spanning tree is A. 30 B. 32 C. 40 D. 42 E. 52
Show worked answer →
Six vertices, so the tree has edges. By inspection, take the smallest edges in turn and skip any that would make a cycle:
, , , and . These five join all six vertices with no cycle ( and would each close a cycle).
Weight : option C ( correct). Prim's algorithm from any vertex gives the same total.
Source: VCAA 2023 General Mathematics Examination 1, Question 35, and the 2023 examination report.
2025 VCAA-style1 markA weighted graph has twelve vertices. Labelling them to (unlabelled in the paper), its edges are , , , , , , , , , , , , , , , and . The minimum spanning tree contains the edge with weight . The length of this minimum spanning tree is A. B. C. D.
Show worked answer →
Twelve vertices need edges. The edge is in the tree, so include it first, then add the smallest remaining edges that do not form a cycle:
, , , , , , , , , .
Skipped: the other 6s ( and ) and , , , , since each would close a cycle.
Length : option B ( correct).
Source: VCAA 2025 General Mathematics Examination 1, Question 35, and the 2025 examination report. (Vertex labels added here; the paper shows the graph.)
Practice questions
Original practice questions graded from foundation to exam level, each with a full worked solution. Try them before revealing the solution.
foundation1 markA connected network has 7 vertices. A spanning tree of this network must contain exactly how many edges? A. 5 B. 6 C. 7 D. 8
Show worked solution →
A spanning tree of a connected network with vertices has exactly edges. Here : option B. More than 6 edges would create a cycle; fewer would leave a vertex disconnected.
foundation2 marksA connected graph has 9 vertices and 14 edges. (a) How many edges must be removed to leave a spanning tree? (b) What is the sum of the degrees of the vertices of that spanning tree?
Show worked solution →
(a) A spanning tree has edges, so remove edges (each chosen to break a cycle without disconnecting the graph). (1 mark)
(b) Sum of degrees . (1 mark)
core3 marksA council must lay cable connecting five sites , , , , . The costs (in thousands of dollars) are , , , , , , . (a) Apply Prim's algorithm starting from , listing the edges in the order they are added. (b) Find the minimum total cost.
Show worked solution →
(a) From : cheapest edge is . From : (add ). From : (add ). Only remains, via , or : add . Order: , , , . (2 marks)
(b) , so $18 000. The tree has edges and no cycle. (1 mark)
core2 marksA network has edges , , , , , , , and . Find the minimum spanning tree and its weight using Prim's algorithm from .
Show worked solution →
From : . From : . From : ( now joins two tree vertices, so it is not a candidate, and and are dearer). From : . Last, : (cheaper than ). (1 mark)
Tree: , , , , , weight . (1 mark)
exam3 marksFive towns are linked by possible roads (km). A dash means no direct road is possible. : 14, 9, 20, -. : 12, -, 8. : 11, 15. : 10. (a) Use Prim's algorithm from to find the minimum length of road needed to connect all five towns. (b) An old road must be kept as part of the network. Find the new minimum total length and the increase.
Show worked solution →
(a) Start at : smallest from is . From : options 14, 20, 12, 11, 15; add . From : is smallest; add . From : ; add . Total km. (2 marks)
(b) Include first, then add the cheapest edges that avoid cycles: , , ( would now close the cycle --). Total km, an increase of km. (1 mark)
exam2 marksIn the seven-vertex network drawn on this page (minimum spanning tree weight 36), a new edge of weight is proposed. For which values of would the minimum spanning tree change, and what would its new weight be?
Show worked solution →
In the current tree the route from to is -----, with edges , , , , . Adding creates a cycle with this route, and the tree improves only if is lighter than the heaviest edge on it, . (1 mark)
So for the new tree swaps for , with weight . For the tree (or its weight, if ) is unchanged. (1 mark)
Practise this
Sources & how we know this
- VCE General Mathematics Examination 1 (2023) and examination report — VCAA (2023)
- VCE General Mathematics Examination 1 (2025) and examination report — VCAA (2025)
- VCE Mathematics Study Design: General Mathematics (from 2023) — VCAA
- VCE General Mathematics: examination specifications, past examinations and reports — VCAA