137 Graph Theory — Optimality
137.1 Overview
This chapter establishes the correctness and optimality of Kruskal’s algorithm on a weighted edge list over the vertex set \(\mathrm{Fin}\, n\): the greedy loop \(\texttt{Kruskal.processEdges}\) preserves the connectivity partition of its input, and the resulting edge set \(\texttt{Kruskal.kruskal}\) spans exactly what the input spans while having minimum total weight among all spanning subsets of the input.
137.2 Declarations
The union–find structure obtained by running the greedy loop over a list of weighted edges: starting from a state \(uf\), each edge \(e\) is merged into the state when its endpoints \(e.u\) and \(e.v\) currently lie in different components, and is ignored otherwise. Unlike \(\texttt{Kruskal.processEdges}\) it returns only the final state, not the list of accepted edges.
For every edge list and every initial state \(uf\), the state \(\texttt{Kruskal.ufAfterProcessEdges}\) produces induces the same partition of the vertices as merging all the edges unconditionally, i.e. it has the same partition as \(uf.\mathrm{mergeAll}\) applied to the whole list.
Running \(\texttt{Kruskal.processEdges}\) with an accumulator \(acc\) yields \(acc^{\mathrm{rev}}\) followed by the output of the same run started from the empty accumulator; the accumulator only contributes a reversed prefix.
Merging the edges selected by the greedy loop into \(uf\) gives the same partition as merging all the input edges into \(uf\): the discarded edges never change connectivity.
If the endpoints of \(e\) already have the same union–find representative, then the greedy loop on \(e :: rest\) from state \(uf\) returns exactly the output of the loop on \(rest\) from the same state.
If the endpoints of \(e\) lie in different components of \(uf\), then the total weight of the greedy output on \(e :: rest\) equals \(e.\mathrm{weight}\) plus the total weight of the greedy output on \(rest\) started from the merged state \(uf.\mathrm{merge}\, e.u\, e.v\).
Let \(uf\) be a union–find state whose classes are exactly the reachability classes of a base edge list, and let the input list \(edges\) be sorted by nondecreasing weight. Then for any competing sublist \(S \subseteq edges\) that induces the same partition as \(edges\) does over \(uf\), the greedy output satisfies
For every weighted edge list \(E\) over \(\mathrm{Fin}\, n\), the output \(\mathrm{kruskal}\, n\, E\) spans like \(E\): any two vertices reachable in \(E\) are reachable using only the selected edges.
If \(S\) is a sublist of \(E\) that spans like \(E\), then
so Kruskal’s output has minimum total weight among all spanning subsets of \(E\).