Proofs: Gomory-Hu tree
These are the human proofs of Gomory-Hu tree, at full length.
Gusfield's method builds a Gomory-Hu tree, and the queries read it correctly full
This proof shows: correctness, termination.
Let be undirected with and weights . For , is the total weight of edges with exactly one end in , so , and is the least with , . We use two facts proved on the page of the Gomory-Hu algorithm: submodularity, , and the triangle inequality, .
Termination. BUILD runs the loop of line L2 exactly times; each iteration runs one maximum flow, which terminates, and a constant number of loops over the vertices. LIGHTEST ends because each iteration replaces the deeper of , by its parent, which lowers , and the walk stops at their lowest common ancestor.
Subtrees. For a vertex , let be the set of vertices whose chain of parents passes through , including .
Invariant. Before the iteration with (and at the end, with ), call processed. Then: (a) the parent of every vertex other than 0 is processed and following parents from any vertex reaches 0; (b) for every processed , .
Read it as a tree whose nodes are the groups for processed , with an edge of weight and witness pair . The set is then the union of the groups on the side of when that edge is removed.
At the start only 0 is processed, every parent is 0, and (b) is empty. Assume the invariant before the iteration with , and let , which is processed, so . Let be the cut of line L4, a minimum - cut with , .
The components of are: for each processed child of , the component with vertex set and top vertex ; and, if , the component containing , with vertex set and top vertex . Each is a minimum cut between its top vertex and a vertex of : for a child , is a minimum - cut by (b); for the parent side, is a minimum - cut by (b). Call this set in each case; it is disjoint from , contains , and does not contain .
Claim 1. There is a minimum - cut with such that for every component , if its top vertex , and otherwise. Proof. Treat the components one by one. If : the set contains and not , so ; submodularity gives , and contains and not , so it is again a minimum - cut. If : the set contains and not , so its value is at least ; submodularity gives , and contains , not . Each step only adds or removes a whole , which is disjoint from and from the other components, so it does not change , the membership of other top vertices, or components already treated.
Claim 2. If the top vertex of a component lies in , then . Proof. By Claim 1, , so contains and not , and . Let be a minimum - cut with , . If , then separates from and . If , then contains and not , so its value is at least , and submodularity gives ; that set contains and not , so . Hence .
The update. Lines L5 and L6 set for every with and . For an unprocessed this moves it from the group of to the group of , so the new groups are and . For a processed child , this moves the component to hang below exactly when its top vertex lies in . Lines L7 and L8 do the same for the parent component: if , it hangs on instead of , and goes below . Now compute the new subtrees.
- The edge between and . If there is no swap, and is together with the components below , which is . If there is a swap, and is together with the components on the side of , which is . Either way the edge has weight , which is by Claim 1, so (b) holds for it.
- A child of that stays: is unchanged, its witness is unchanged.
- A child moved to : is unchanged, and by Claim 2 .
- The parent edge after a swap: the edge is now with the old and the old . Its subtree is minus the parent component, the same set as the old , so equals the old , and by Claim 2, equals it too. Without a swap the parent edge of is unchanged.
- All other edges keep their subtrees.
After the update is processed, every parent is processed, and the parent chains still reach 0: the only changes point vertices at , whose own chain avoids them, or make the parent of while takes the old parent of . So the invariant holds before the next iteration.
The tree at the end. After the last iteration every vertex is processed and every group is a single vertex. For each edge , (b) says . Take and the tree path . Each edge on the path has a subtree containing exactly one of , , so is at most its weight. By the triangle inequality along the path, , the least edge weight on the path. So equals the least weight on the path, and the subtree of a lightest path edge, or its complement, is a minimum - cut.
The queries. LIGHTEST moves the deeper of and to its parent until they meet; the edges it passes are exactly the edges of the tree path, each once, and it returns the lower end of a lightest one. MIN-CUT-VALUE returns . MIN-CUT returns or its complement, whichever holds ; it does not hold , since the edge lies on the path, and its value is . GLOBAL-MIN-CUT picks the lightest edge of the tree; every global cut separates some pair and so has value at least , which is at least the lightest tree weight, and attains it.