TCSLib

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

Definition 137.1 Union–find state after the greedy loop

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.

Lemma 137.2 Greedy loop induces the full merge partition

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.

Lemma 137.3 Accumulator factors out of the greedy loop

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.

Lemma 137.5 Skipping an edge inside a component

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.

Lemma 137.6 Weight contributed by an accepted edge

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

\[ \mathrm{totalWeight}\bigl(\mathrm{processEdges}\; edges\; uf\; [\, ]\bigr) \; \le \; \mathrm{totalWeight}(S). \]
Theorem 137.8 Kruskal’s output spans the input

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.

Theorem 137.9 Optimality of Kruskal’s algorithm

If \(S\) is a sublist of \(E\) that spans like \(E\), then

\[ \mathrm{totalWeight}\bigl(\mathrm{kruskal}\; n\; E\bigr) \; \le \; \mathrm{totalWeight}(S), \]

so Kruskal’s output has minimum total weight among all spanning subsets of \(E\).