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.
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.
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.
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 (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.
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 .
Proof moves used here.
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
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.
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.
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.
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.
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.
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.
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.
node_disjoint_paths and edge_disjoint_paths find disjoint
paths with maximum-flow computations, and minimum_node_cut returns the matching cut.After the lab, the tutor will ask you to defend your work out loud:
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.