Sub topic 5
The Cycle Property: Which Edges Can Never Be in an MST
This chapter assumes you know what a minimum spanning tree (MST) is and have seen the cut property. You should also be comfortable with cycles, edge lists, and basic Python.
The cut property tells you which edges are safe to add. The cycle property works from the other side and tells you which edges you can throw away.
Statement of the Cycle Property
Take any cycle C in a weighted undirected graph. If an edge e on C is strictly heavier than every other edge on C, then e is in no MST.
If e only ties for heaviest on C, a weaker claim holds: at least one MST leaves e out. Other MSTs may still contain it.
Why It Holds: An Exchange Argument
Suppose an MST T contains e = (u, v), where e is the unique heaviest edge on cycle C.
- Remove e from T. The tree splits into two components, one containing u and one containing v.
- The rest of C is a path from u to v that avoids e. That path starts on u's side and ends on v's side, so at least one of its edges, f, crosses between the two components.
- Add f. The result T − e + f is again a spanning tree.
- Because w(f) < w(e), the new tree is lighter than T. That contradicts T being minimal.
This is the same swap used to prove the cut property, applied in reverse.
A Worked Example
The four-vertex graph below appears throughout the tutorial.
| Cycle | Edge weights | Heaviest edge | Conclusion |
|---|---|---|---|
| 0-1-2 | 1, 3, 4 | (0, 2) weight 4 | Never in an MST |
| 1-2-3 | 3, 2, 5 | (2, 3) weight 5 | Never in an MST |
Three edges remain, with weights 1, 2, and 3. Three edges on four vertices with no cycle form a spanning tree, so they are the MST, with total weight 6.
Using the Property as an Algorithm
The reverse-delete algorithm applies the cycle property over and over. It visits edges from heaviest to lightest and deletes each one whose removal keeps the graph connected. An edge can be removed without disconnecting the graph only when it lies on a cycle. All heavier edges have already been considered, so the current edge is the heaviest one still on that cycle.
from collections import deque
def connected(n, edges):
adj = [[] for _ in range(n)]
for _, u, v in edges:
adj[u].append(v)
adj[v].append(u)
seen = [False] * n
seen[0] = True
queue = deque([0])
while queue:
x = queue.popleft()
for y in adj[x]:
if not seen[y]:
seen[y] = True
queue.append(y)
return all(seen)
def reverse_delete(n, edges):
# edges: list of (weight, u, v); graph assumed connected
kept = sorted(edges, reverse=True)
i = 0
while i < len(kept):
trial = kept[:i] + kept[i + 1:]
if connected(n, trial):
kept = trial # edge was on a cycle and heaviest there
else:
i += 1 # edge is a bridge; it must stay
return sum(w for w, _, _ in kept), sorted(kept)
edges = [(1, 0, 1), (4, 0, 2), (3, 1, 2), (2, 1, 3), (5, 2, 3)]
print(reverse_delete(4, edges)) # (6, [(1, 0, 1), (2, 1, 3), (3, 1, 2)])This version runs a full connectivity check for each edge, so it costs O(E·(V + E)). That is too slow for real use. Its purpose is to show the cycle property working on its own. Kruskal's and Prim's algorithms, covered in later chapters, are the practical choices.
Common Errors
- Ignoring ties. If two edges tie for heaviest on a cycle, you may drop one of them, but not both by the same argument.
- Reasoning about a single cycle. An edge that is heaviest on one cycle is excluded, even if it is light on other cycles. You only need one cycle where it is strictly heaviest.
Exercise
Add an edge (0, 3) with weight 2.5 to the example graph. Which edge does the cycle 0-1-3 eliminate, and what is the new MST weight?
Show answer
Cycle 0-1-3 has weights 1, 2, and 2.5, so it eliminates (0, 3). The edges (0, 2) and (2, 3) are still excluded by their own cycles, so the MST stays {1, 2, 3} with weight 6.
Exercise
In a graph where every cycle has a unique heaviest edge, explain why deleting every such edge leaves a spanning tree.
Show answer
Every remaining edge is the lightest-or-only option somewhere, and any surviving cycle would have a unique heaviest edge that should have been deleted. So no cycles remain. Deleting an edge on a cycle never disconnects the graph, so the result is connected and acyclic, which makes it a spanning tree.