Chapter 9

Minimum spanning treesCS

An MST minimizes the total weight of a spanning tree in a connected undirected graph. Edge weights may be negative, zero or repeated. For a disconnected graph the corresponding object is a minimum spanning forest, one tree per component.

9.1 Cut and cycle propertiesCS

Past papers · CS 2014–2026 (23 papers): 11 questions, 20 marks

A cut separates the vertex set into two nonempty parts. A crossing edge joins those parts. A spanning tree has nv−1n_v-1 edges. Do not confuse minimum total tree weight with minimum root-to-vertex distances.

Distinct weights are sufficient, not necessary, for uniqueness. A unique lightest edge on every cut is also sufficient. The lightest edge on a cycle need not belong to every MST. With ties, even a globally minimum-weight edge need not be compulsory: an equal-weight triangle provides a counterexample.

For simple graphs with distinct weights, the two globally lightest edges cannot form a cycle, so Kruskal accepts both. Among the third and fourth lightest edges, at least one is accepted: if the third closes a triangle, a distinct fourth edge in a simple graph cannot connect another unused pair inside that same three-vertex component.

9.2 Prim and KruskalCS

Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks

Prim grows one tree; Kruskal grows a forest. Both use greedy safe-edge choices, but their priority values differ from Dijkstra's path distances.

Prim stores for each outside vertex the lightest edge connecting it to the current tree, not the sum along a source path. A new key is min⁡(key[v],w(u,v))\min(\mathrm{key}[v],w(u,v)). Kruskal sorts all edges by nondecreasing weight, rejects a cycle-forming edge, and stops after nv−1n_v-1 acceptances in a connected graph. With ties, either method may return different trees but the same minimum total weight.

A minimum spanning forest needs nv−cn_v-c accepted edges for cc components. Prim must restart from each unvisited component; Kruskal naturally leaves those components separate.

9.3 Updates, uniqueness and countingCS

Past papers · CS 2014–2026 (23 papers): 7 questions, 12 marks

A tree has a unique path between two vertices. Adding one extra edge creates exactly one cycle, so checking its maximum-weight tree edge determines whether an exchange improves the tree.

An MST TT is unique exactly when every non-tree edge uvuv is strictly heavier than the maximum edge on PT(u,v)P_T(u,v). If a non-tree edge decreases in weight, use the same path test. If a tree edge is removed or increases, remove it and find the lightest edge reconnecting the two resulting parts. A decrease of a tree-edge weight or increase of a non-tree-edge weight cannot destroy the optimality of the current tree.

To count MSTs, process one equal-weight batch at a time. First contract all components already connected by lighter edges. In the graph of current-weight edges between those components, select a spanning tree in each connected piece; multiply the numbers of choices across pieces and batches. Retain parallel edges after contraction because they represent distinct original choices. For small graphs enumerate subsets and test connectivity/acyclicity. Do not multiply the number of tied edges independently when their selections can form a cycle.

Strictly increasing transformations preserve edge order and all MST choices, even if nonlinear. They need not preserve shortest paths, which compare sums. For any vertices u,vu,v, graph shortest distance is at most their route distance in a spanning tree, since the tree route is also a graph route.

Adding an edge creates one cycle; compare its weight with the largest tree-edge weight on that cycle.Adding an edge creates one cycle; compare its weight with the largest tree-edge weight on that cycle.

Last-minute recall

  • MSTs concern connected undirected graphs; otherwise use a forest.
  • Negative edge weights are allowed for MST algorithms.
  • Unique cut minimum means compulsory; unique cycle maximum means excluded.
  • Equal weights permit, but do not force, multiple MSTs.
  • Prim keys are connecting-edge weights, not path lengths.
  • Kruskal checks disjoint sets before accepting an edge.
  • New-edge updates inspect the maximum on one tree path.
  • Adding the same constant to every edge preserves MSTs.
  • Count equal-weight choices after contracting lighter components.

Revise offline: the whole Algorithms handbook as one PDF

52 pages · 2.6 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections