Menger's Theorem
The question
Here is the prism from module 15 again: the outer triangle , the inner triangle , and the rungs –, –, –.
How many routes from router to router can you find that share no router in between? The picture shows three. Could there be four? No: router has only three neighbors, and every route leaves through one of them. So deleting the three routers cuts off from , and that set of three is a certificate that no fourth route exists.
So here two numbers coincide: the most routes that avoid each other, and the fewest routers whose removal separates from . Menger's theorem says they always coincide. It is the connectivity version of module 11's matching–cover pair: two certificates of the same size that prove each other optimal.
The naive approach, and where it wastes work
from itertools import combinations
from collections import deque
def network(edges):
g = {}
for u, v in edges:
g.setdefault(u, set()).add(v)
g.setdefault(v, set()).add(u)
return g
def reachable(g, x, y, removed=()):
gone, seen, queue = set(removed), {x}, deque([x])
while queue:
u = queue.popleft()
for w in g[u]:
if w not in gone and w not in seen:
seen.add(w)
queue.append(w)
return y in seen
def min_cut(g, x, y):
"""Fewest vertices other than x, y whose deletion separates them (brute force)."""
others = [v for v in g if v not in (x, y)]
return next(k for k in range(len(others) + 1)
for S in combinations(others, k) if not reachable(g, x, y, S))
prism = network([(0, 1), (1, 2), (2, 0), (3, 4), (4, 5), (5, 3), (0, 3), (1, 4), (2, 5)])
assert 4 not in prism[0] and min_cut(prism, 0, 4) == 3
Searching every set of routers doubles the work with each router added, and its answer, "the minimum is 3", is only believable if you rerun it. Three explicit routes and three explicit routers are believable at a glance. The theorem promises both always exist.
Cuts and disjoint paths
Let and be non-adjacent vertices of a graph . An -cut is a set of vertices, not containing or , such that has no -path. Write for the minimum size of an -cut, and for the maximum number of pairwise internally disjoint -paths (paths sharing no vertex other than and ).
One inequality is easy: . Every -cut contains an internal vertex of each of the paths, and since the paths are internally disjoint, these vertices are distinct.
Predict: a graph has 3 internally disjoint -paths and an -cut of 4 vertices. What is ?
All you know is . The two objects bound the answer from both sides but do not meet, so neither is a certificate yet. Menger's theorem promises that a family and a cut of the same size exist; finding them settles the question.
The requirement that and be non-adjacent matters: if is an edge, no set of other vertices can separate them, and the path has no internal vertex at all.
Menger's theorem
Menger's theorem (1927)
If and are non-adjacent vertices of a graph , then the minimum size of an -cut equals the maximum number of pairwise internally disjoint -paths: .
Proof. We have . For we show, by induction on the number of vertices, that there are internally disjoint -paths. If there is nothing to show, so let .
Case 1: some minimum -cut is neither nor . Call a path from that meets only at its last vertex an -path, and define -paths the same way. Let be the set of vertices on -paths and the set of vertices on -paths.
- . Each is in both: since is a minimum cut, is not a cut, so some -path meets only at , and its two halves are an -path and a -path ending at . A vertex outside in both sets would give a walk from to that avoids . For the same reason and .
- Build from by adding a new vertex adjacent to every vertex of , and from by adding adjacent to . Every -cut of is an -cut of : an -path of avoiding it would reach , and its part up to its first vertex of is an -path, which lies in . So , and likewise for .
- has fewer vertices than : it adds only , and has at least two vertices outside . One is . For a second: if some is not adjacent to , an -path meeting only at has a vertex strictly between and , on a -path and outside , so not in . Otherwise , and since , has a neighbor outside , which is not in either (it would give an -path avoiding ). Similarly for , using .
By induction has internally disjoint -paths. Their vertices just before are distinct vertices of , so they are all of , and no path contains a second vertex of (it would share that vertex with another path). Dropping leaves -paths ending at distinct vertices of . In the same way gives -paths. Joining the two paths that end at each gives -paths in , internally disjoint because the -halves lie in , the -halves in , and , with each vertex of used once.
Case 2: every minimum -cut is or .
- If some vertex is neither , , nor a neighbor of either, delete it. If had an -cut with fewer than vertices, then would be an -cut of with at most vertices, hence a minimum one, and it contains , so it is neither nor , contradicting the case. Hence , and induction gives paths.
- If some is adjacent to both and , it lies in every -cut, so . Induction gives paths in ; add the path .
- Otherwise and split the other vertices. Let be the bipartite graph of edges of between and . A set of other vertices is an -cut exactly when it covers every edge of : an uncovered edge gives the path , and every -path must cross from to along an edge of . So the minimum vertex cover of has size , and by König–Egerváry (module 11) has a matching of edges . The paths are internally disjoint.
Proof moves used here.
- Induction on the number of vertices, with the cases arranged so the smaller graphs really are smaller.
- Decomposition: in Case 1, cut the graph at a minimum cut, solve each side, and glue.
- Certificate pair: the base case is König–Egerváry, the matching–cover duality of module 11.
- Case split on how the minimum cuts sit, so every situation is covered once.
Traced on the prism
For and the neighborhood is a minimum cut, and so is , and there is no other, so the proof runs Case 2. The vertices 1 and 3 are common neighbors: the proof deletes 1, finds two paths in what remains (deleting 3 the same way leaves the single path ), and adds back and . The three routes in the picture are the result:
paths = [[0, 1, 4], [0, 3, 4], [0, 2, 5, 4]]
assert all(all(b in prism[a] for a, b in zip(p, p[1:])) for p in paths)
inner = [set(p[1:-1]) for p in paths]
assert all(not inner[i] & inner[j] for i in range(3) for j in range(i + 1, 3))
assert len(paths) == min_cut(prism, 0, 4) == 3
Every pair: the global version
Theorem. A graph with at least vertices is -connected if and only if every two vertices of are joined by pairwise internally disjoint paths.
Proof. If. Deleting fewer than vertices leaves at least one of the paths between any two remaining vertices intact, so the rest stays connected.
Only if. Let be -connected and two vertices. If they are non-adjacent, every -cut is a separating set, so , and Menger gives paths. If is an edge, look at , where and are non-adjacent. Let be an -cut of ; we show . Suppose . In , let be the component of and the component of . Since is connected (), the edge is the only link between and , and every other vertex lies in or . There is such a vertex, because . If some is in , then separates from in , a separating set of at most vertices; if some is in , use . Either way is not -connected, a contradiction. So , Menger gives internally disjoint paths in , and the edge is the -th.
Proof move used here. Quantifiers matter: the local theorem is about one pair; the global one needs the local one for every pair, including the adjacent ones, which need their own argument.
Cutting edges instead: the edge version
The same holds for edges. For distinct vertices , the minimum number of edges whose deletion separates them equals the maximum number of pairwise edge-disjoint -paths. One way to see it: attach new vertices to and to , and apply the vertex version to the line graph, whose vertices are the edges of ; edge-disjoint paths and edge cuts of become internally disjoint paths and vertex cuts there. We sketch this and do not prove it here; module 17 proves the edge version again with flows. As before, is -edge-connected exactly when every two vertices are joined by edge-disjoint paths.
Predict: for non-adjacent , is the number of edge-disjoint -paths at least the number of internally disjoint ones?
Yes. Since is not an edge, every edge of an -path has an internal vertex of that path as an endpoint, so paths that share no internal vertex share no edge. The edge version's answer is at least the vertex version's, and it can be larger; module 17 returns to this.
The Fan Lemma
A tool that the next modules use often:
Fan Lemma. If is -connected, is a vertex, and is a set of at least vertices not containing , then there are paths from to distinct vertices of that share only the vertex (a fan).
You will prove it in the lab, from Menger's theorem.
What a certificate costs
internally disjoint paths and an -cut of size are each checked in time, and together they prove . Searching every set of vertices costs up to reachability tests. Finding a family and a cut together needs no such search: the lab's first exercise grows both with about reachability searches, and module 17's flows extend the idea.
A problem that looks different
In a city, the town hall stands at one end and the train station at the other. Engineers ask how many streets must close before no route between them remains, and how many routes can be kept open at once without sharing a street. Then they ask the same about every pair of buildings in the city at once. Nothing in the question mentions cuts or disjoint paths. The lab's last exercise is another question like that.
Practise
The lab runs in your browser. Your code grows a family of routes that share no street and reads off a cut of the same size, then finds routes that share no router with a tool built only for streets. Half of the lab is proofs: assemble the proof of the Fan Lemma, find the false step in an argument about connectivity, and write a proof for a problem that names no technique.
Recap
- You can now: define and ; prove ; prove Menger's theorem by induction, with König–Egerváry as the base case; prove the global version, including adjacent pairs; and state the edge version and the Fan Lemma.
- Invariant: every -cut meets each of a family of internally disjoint paths in a different vertex, so a family of paths and a cut of size prove each other optimal.
- Complexity achieved: both certificates are checked in , against up to vertex sets for a brute-force minimum cut.
- Failure mode: treating disjoint paths between one pair as proof that the whole graph is -connected; and forgetting that adjacent vertices have no vertex cut.
- In real software: NetworkX's
node_disjoint_pathsandedge_disjoint_pathsfind disjoint paths with maximum-flow computations, andminimum_node_cutreturns the matching cut. - Retrieval: module 14 bounded above by an explicit separating set. What is the matching lower-bound certificate? (For every pair of vertices, internally disjoint paths.)
Check yourself
After the lab, the tutor will ask you to defend your work out loud:
- In Case 1, why does guarantee that is smaller than ?
- Why does the base case need König–Egerváry, and where exactly do the bipartite graph's vertex covers come from?
- In the global version, why does an adjacent pair need a separate argument, and where is used?
Topic list modeled on the public syllabus of UIUC Math 412 (Graph Theory), which follows D. B. West, Introduction to Graph Theory, 2nd ed., Chapters 1–7. All lessons, proofs, examples, code and exercises here are original. This course is independent and not affiliated with or endorsed by the University of Illinois.