The maximal-matching 2-approximation for vertex cover #
This module formalizes the classical 2-approximation for minimum vertex cover: greedily build a
maximal matching and return both endpoints of every matching edge ([CLRS09], Section 35.1,
APPROX-VERTEX-COVER and Theorem 35.1).
Model #
The graph is SimpleGraph.fromRel (fun u v => (u, v) ∈ es) for a list es : List (V × V) of edges
over a type with decidable equality: two distinct vertices are adjacent when some listed edge joins
them in either direction. Self-loops and repeated edges may occur in es; the graph ignores them.
Covers and the optimum are Mathlib's SimpleGraph.IsVertexCover and
SimpleGraph.vertexCoverNum.
Algorithm and source mapping #
greedyMatching es scans es once, keeping an edge (u, v) when u ≠ v and neither endpoint is
already matched; matchingCover es lists the endpoints of the kept edges. [CLRS09]'s
APPROX-VERTEX-COVER repeatedly picks an arbitrary remaining edge, adds both endpoints to the
cover and deletes the edges incident to them; the scan makes the same choices with "arbitrary"
read as "first remaining edge in list order", since an edge is still present exactly when neither
endpoint has been matched. The analysis is the source's: the kept edges form a matching
(nodup_matchingCover), every vertex cover contains a distinct endpoint of each of them
(length_le_encard_of_isVertexCover), and the returned cover has exactly two vertices per kept
edge (length_endpoints).
Limitations #
The algorithm is a pure Lean function; a machine-level running time for the Graph encoding is
in CslibFrontier.Computability.Complexity.Problems.VertexCover.Approximation.
Main definitions #
Cslib.Algorithms.Lean.VertexCover.endpoints: the endpoints of a list of edges.Cslib.Algorithms.Lean.VertexCover.greedyMatching: the greedy maximal matching.Cslib.Algorithms.Lean.VertexCover.matchingCover: its endpoints, the returned cover.Cslib.Algorithms.Lean.VertexCover.coverStep: the scan step tracking only matched vertices.
Main results #
isVertexCover_matchingCover: the returned vertices cover every edge.nodup_matchingCover,mem_matchingCover: the returned vertices are distinct endpoints of listed edges.matchingCover_eq_foldl_coverStep: the cover is a single scan tracking only matched vertices.length_le_encard_of_isVertexCover: a matching has at most as many edges as any vertex cover has vertices.length_matchingCover_le_two_mul_encard,length_matchingCover_le_two_mul_card,length_matchingCover_le_two_mul_vertexCoverNum: the returned cover has at most twice as many vertices as any vertex cover, in particular a minimum one.
References #
The algorithm #
One step of the greedy matching: keep the edge e when its endpoints are distinct and both
unmatched by M. Kept edges are appended, so the matching lists them in scan order.
Greedy maximal matching: scan the edges once, keeping each edge whose endpoints are distinct and not yet matched.
The matching cover: both endpoints of every edge of the greedy maximal matching.
One step of the scan that tracks only the matched vertices C: add both endpoints of e when
they are distinct and unmatched.
Invariants of the greedy scan #
The scan only adds edges: the initial matching is contained in the final one.
The scan keeps the endpoints of the matching distinct.
Every edge of the final matching is in the initial matching or is a listed edge with distinct endpoints.
Maximality. Every listed edge with distinct endpoints meets the final matching.
Scanning with matchingStep and taking endpoints is scanning with coverStep.
The matching cover is computed by the scan that tracks only the matched vertices.
The returned vertices are distinct, so the returned list has the cover's size.
The greedy matching consists of listed edges with distinct endpoints.
The returned vertices are endpoints of listed edges.
Correctness and the factor 2 #
Feasibility. The matching cover is a vertex cover.
The matching lower bound. A list of edges of G with pairwise distinct endpoints has at
most as many edges as any vertex cover of G has vertices: each edge has an endpoint in the cover,
and distinct edges have distinct endpoints.
The factor 2 against any cover. The matching cover has at most twice as many vertices as any vertex cover.
The factor 2 against any finite cover.
The maximal-matching 2-approximation: the matching cover has at most twice the minimum number of vertices in a vertex cover.