MST Variants & Applications
Bottleneck paths, second-best trees, Kruskal reconstruction trees and clustering.
A minimum spanning tree is more than a cheap network. The path it gives between any two vertices makes the heaviest edge on the route as light as possible, so one tree answers all bottleneck questions; deleting its heaviest edges yields the clusters with the widest gaps; and replaying Kruskal's merges as a tree turns "where can I go on edges of weight at most ?" into a subtree lookup.
What you’ll learn
- Prove that MST paths are minimum-bottleneck paths, certified by a cut, and that every MST is a minimum bottleneck spanning tree but not conversely.
- Prove that a second-best spanning tree is one swap away from an MST, compute it in or , and decide which edges lie in some or in every MST.
- Build a Kruskal reconstruction tree and use it for bottleneck and threshold-reachability queries.
- Prove that single-linkage clustering maximizes the spacing, and use MSTs for Euclidean networks, Steiner trees and the traveling salesman.
Bottleneck paths
Let be the heaviest edge on the -path from to . Deleting splits into two parts, which define a cut with and on opposite sides.
is a lightest edge across that cut, for otherwise swapping it for a lighter crossing edge would give a lighter spanning tree .
Every path from to in crosses the cut somewhere, so its bottleneck is at least , which the tree path attains. The argument never assumed distinct weights.
In the graph with edges A–B 3, A–C 4, B–C 1, B–D 7, C–D 5, B–E 10, D–E 2, D–F 8, C–F 11, E–G 6 and F–G 9, what is the smallest possible weight of the heaviest edge on a route from A to G?
Show the answer
6
The MST path A–B–C–D–E–G uses weights 3, 1, 5, 2, 6, so the answer is at most 6. It is at least 6 because the edges lighter than 6 (B–C, D–E, A–B, A–C, C–D) connect only A, B, C, D and E: G cannot be reached without an edge of weight 6 or more.
The converse fails. In the triangle A–B 1, B–C 2, A–C 2, the tree B–C, A–C has bottleneck 2, as small as possible, but weight 4, while the MST weighs 3. An MBST can even be found in time, faster than any known deterministic MST algorithm, by repeatedly comparing the edge weights with their median and contracting (Camerini, 1978).
Answering queries. For one pair, run Dijkstra's algorithm with in place of , as in the shortest-paths lesson, or read the path off an MST. For all pairs, one traversal of the MST from each vertex gives every in . For many online queries, binary lifting on the MST answers each in , and the Kruskal reconstruction tree of step 3 does even better.
Second-best trees, and which edges matter
Take a second-best tree and an edge . Deleting from defines a cut; the -path between 's ends crosses it with an edge . Both swaps give spanning trees:
is minimum, so . If , then is a single swap. Otherwise is a tree different from , and is second-best, so :
So is another second-best tree, with one more edge in common with . Repeating ends at a second-best tree . For a fixed non-tree edge , the cheapest such swap removes the heaviest edge on 's tree path:
def second_best(n, edges):
"""Connected graph, edges = [(w, u, v), ...]. Returns (MST weight, second-best weight).
Uses the DSU class of the Optimized lesson. O(n^2 + m log m) time, O(n^2) memory."""
dsu, total, adj, rest = DSU(n), 0, [[] for _ in range(n)], []
for w, u, v in sorted(edges):
if dsu.union(u, v): # Kruskal: a tree edge
total += w
adj[u].append((v, w)); adj[v].append((u, w))
elif u != v:
rest.append((w, u, v)) # a non-tree edge
heaviest = [[float('-inf')] * n for _ in range(n)] # max weight on the tree path s..x
for s in range(n):
stack = [s]
while stack:
x = stack.pop()
for y, w in adj[x]:
if y != s and heaviest[s][y] == float('-inf'):
heaviest[s][y] = max(heaviest[s][x], w)
stack.append(y)
return total, min((total + w - heaviest[u][v] for w, u, v in rest), default=None)One traversal of the tree from each vertex tabulates every path maximum, which suits dense graphs. For large sparse graphs, binary lifting stores the maximum edge on each jump of steps toward the root and answers each path-maximum query in : in all. If the second-best weight must be strictly larger than , keep the largest and the second-largest distinct weights on each jump, and use the second whenever the largest equals .
This classifies all edges in : process the weight classes in Kruskal's order. Within a class, an edge whose ends are already joined by lighter edges is in no MST. The others live in the multigraph whose vertices are the components formed by the lighter edges; among them, exactly the bridges of that multigraph are in every MST, and the rest are in some but not all. Bridges come from one depth-first search per class (see Bridges, Articulation Points & Biconnectivity); then union the class and move on.
Kruskal reconstruction trees
Run Kruskal's algorithm, but each time an edge of weight merges two components, create a new node with value whose two children are the trees of those components. The original vertices are the leaves. On a connected graph the result is a binary tree with leaves and internal nodes: the Kruskal reconstruction tree, a record of the order in which the graph comes together.
def kruskal_tree(n, edges):
"""Leaves 0..n-1 are the vertices; each merge by an edge of weight w adds a node of value w.
Returns up (parent pointers; a root points to itself), value, and leaves (leaf count)."""
comp = list(range(2 * n)) # union-find over tree nodes
def find(x):
while comp[x] != x:
comp[x] = comp[comp[x]]
x = comp[x]
return x
up, value, leaves = list(range(2 * n)), [0] * (2 * n), [1] * n + [0] * n
new = n
for w, u, v in sorted(edges):
a, b = find(u), find(v)
if a == b:
continue
value[new], leaves[new] = w, leaves[a] + leaves[b]
up[a] = up[b] = comp[a] = comp[b] = new # the new node adopts both components
new += 1
return up, value, leaves
def reachable(up, value, leaves, v, W):
"""How many vertices can v reach using only edges of weight <= W?"""
while up[v] != v and value[up[v]] <= W: # binary lifting makes this O(log n)
v = up[v]
return leaves[v]The climb is written as a loop for clarity; with binary lifting over up, each query takes after preprocessing, and lowest common ancestors give bottlenecks in or, with an Euler tour and a sparse table, (see Lowest Common Ancestors).
On the graph of step 1 (A–B 3, A–C 4, B–C 1, B–D 7, C–D 5, B–E 10, D–E 2, D–F 8, C–F 11, E–G 6, F–G 9), how many vertices, A included, can A reach using only edges of weight at most 7?
Show the answer
6
The tree's internal nodes have values 1, 2, 3, 5, 6, 8 (B–C, D–E, A–B, C–D, E–G, D–F). From A, climb through 3, 5 and 6 and stop below 8: the node of value 6 covers A, B, C, D, E and G. F needs D–F 8 or more. The edge B–D 7 is allowed but changes nothing: it joins two vertices already connected.
What it is used for. "Starting from , which places can you reach on roads with weight limit at least your truck's weight?" (build the tree from a maximum spanning tree, in decreasing order). "Drive on the roads that are still above water, then walk": compute walking distances to the destination with Dijkstra's algorithm, store at each tree node the minimum over its leaves, and every query is one climb. Since the leaves below any node form a contiguous range in a depth-first order, a segment tree or a persistent structure over that order answers "the -th largest value among reachable vertices" as well.
Offline, the same questions can be answered by sorting queries by and adding edges to a union-find structure as grows; the reconstruction tree answers them online, in any order.
Clustering, geometry and approximation
Let be Kruskal's clustering, and the length of the edge Kruskal would add next; that edge joins two different clusters, so has spacing .
Take any other -clustering . Some cluster of contains two points that separates. Kruskal connected them inside that cluster by a path of edges, each of length at most , since each was added before the edge of length .
The path starts in one cluster of and ends in another, so some step joins two different clusters of :
On the graph of step 1, whose MST is B–C 1, D–E 2, A–B 3, C–D 5, E–G 6, D–F 8, you delete the two heaviest MST edges to get three clusters. What is their spacing?
- 8
- 5
- 6
- 9
Show the answer
C. 6
Deleting D–F 8 and E–G 6 leaves the clusters , and . The edges between different clusters are E–G 6, D–F 8, F–G 9 and C–F 11, so the spacing is 6, the weight of the second heaviest MST edge, which is exactly what the theorem predicts.
Geometric MSTs. For points in the plane, the Euclidean MST is a subgraph of the Delaunay triangulation, which has at most edges and can be built in , so the EMST takes time instead of (Shamos & Hoey, 1975). That is optimal in the algebraic decision-tree model, because the EMST's shortest edge is the closest pair. In contests the Manhattan-distance MST uses the same idea: each point only needs an edge to its nearest neighbor in each of 8 octants, which leaves candidate edges.
The same doubling argument makes a doubled MST, shortcut along an Euler tour, a 2-approximation for the metric traveling salesman problem; Christofides and Serdyukov add a minimum-weight matching on the odd-degree vertices to reach . The lesson Approximating the Traveling Salesman develops both, and the 2021 improvement below .
Key takeaways
- In any MST, the tree path between two vertices minimizes the heaviest edge, and a cut certifies it; every MST is a minimum bottleneck spanning tree, but not conversely.
- A second-best spanning tree is for one non-tree edge and the heaviest edge on its tree path: with one traversal per vertex, with binary lifting. An edge is in some MST iff lighter edges do not connect its ends, and in every MST iff it is a bridge of its weight class after contracting the lighter edges.
- The Kruskal reconstruction tree has nodes; the value at is the bottleneck , and the vertices reachable from with edges of weight are the leaves below one ancestor.
- Stopping Kruskal at components gives the -clustering of maximum spacing; planar Euclidean MSTs take through the Delaunay triangulation; an MST of the terminals' metric closure is within of an optimal Steiner tree.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Every MST is a minimum bottleneck spanning tree. Is every minimum bottleneck spanning tree an MST?
- Yes: a tree whose heaviest edge is minimum must have minimum total weight
- Only when the graph is complete
- Yes, if all weights are distinct
- No: in the triangle A–B 1, B–C 2, A–C 2, the tree A–C, B–C has the minimum bottleneck 2 but weight 4, more than the MST's 3
Show the answer
D. No: in the triangle A–B 1, B–C 2, A–C 2, the tree A–C, B–C has the minimum bottleneck 2 but weight 4, more than the MST's 3
The bottleneck only constrains the heaviest edge; the lighter edges of an MBST can be wasteful. That freedom is why an MBST can be found in linear time while finding an MST deterministically in linear time is open.
Edge has weight 5. The edges of weight less than 5 do not connect and , but after deleting , another path of edges of weight at most 5 still does. Then is...
- in some minimum spanning trees but not in all of them
- in every minimum spanning tree
- in no minimum spanning tree
- in the MST only if it is a bridge of the whole graph
Show the answer
A. in some minimum spanning trees but not in all of them
No strictly lighter path joins its ends, so is a lightest edge across some cut and can be in an MST. But another path of weight- edges exists, so some edge of weight exactly 5 on it can replace : not every MST needs it.
In a Kruskal reconstruction tree, what is the value stored at the lowest common ancestor of two leaves and ?
- The shortest-path distance between and
- The minimum bottleneck : the least possible weight of the heaviest edge on a – path
- The weight of the MST path between and
- The number of edges on the MST path between and
Show the answer
B. The minimum bottleneck : the least possible weight of the heaviest edge on a – path
That node was created by the edge that first connected 's and 's components during Kruskal's scan, and every lighter edge had already been tried, so it is the smallest possible heaviest edge, .
You have an MST and add a non-tree edge . To get the cheapest spanning tree that contains , which edge do you remove?
- The heaviest edge of the whole tree
- The lightest edge on the -path from to
- Any edge on the cycle; they all give the same weight
- The heaviest edge on the -path from to
Show the answer
D. The heaviest edge on the -path from to
Adding creates exactly one cycle, plus the tree path; removing any edge of that path restores a spanning tree, and removing the heaviest one keeps the total smallest. Minimizing over all non-tree edges gives a second-best tree.
Further reading
- J. C. Gower & G. J. S. Ross, "Minimum spanning trees and single linkage cluster analysis," Journal of the Royal Statistical Society, Series C (Applied Statistics) 18(1) (1969), 54–64.
- M. I. Shamos & D. Hoey, "Closest-point problems," Proceedings of the 16th IEEE Symposium on Foundations of Computer Science (1975).
- L. Kou, G. Markowsky & L. Berman, "A fast algorithm for Steiner trees," Acta Informatica 15 (1981), 141–145.
- J. Kleinberg & É. Tardos, Algorithm Design (Addison-Wesley, 2005), section 4.7.
- T. H. Cormen, C. E. Leiserson, R. L. Rivest & C. Stein, Introduction to Algorithms, 4th ed. (MIT Press, 2022), chapter 21 and its problems.