A Near-Optimal Vertex Cover with Approximation Ratio Under : The Varela Algorithm
Frank Vega
Information Physics Institute, 840 W 67th St, Hialeah, FL 33012, USA
vega.frank@gmail.com
Introduction
The Minimum Vertex Cover (MVC) problem is a fundamental challenge in graph theory and combinatorial optimization. Given an undirected graph with vertices and edges, a vertex cover is a subset such that every edge has at least one endpoint in (i.e., for all , or ). The goal is to find a vertex cover with minimum cardinality, denoted , also written . MVC is NP-hard, making exact solutions computationally infeasible for large graphs, which motivates approximation algorithms. Applications include network monitoring (placing sensors to observe every link), circuit testing, and bioinformatics.
The connection to the Maximum Independent Set (MIS) problem is exact:
where is the independence number. Every minimum vertex cover is the complement of a maximum independent set, and vice versa.
Key results in the state of the art include:
- 2-Approximation (classical): The greedy algorithm — repeatedly pick any uncovered edge and add both its endpoints — achieves ratio in time. This is tight under the Unique Games Conjecture (UGC).
- Unique Games Conjecture (UGC): Khot and Regev showed that, assuming the UGC, no polynomial-time algorithm can achieve a ratio below for any . Breaking the ratio-2 barrier in polynomial time would therefore constitute a disproof of the UGC.
- Unconditional lower bounds: Even without the UGC, achieving ratio below is NP-hard (Dinur–Safra).
- Special classes: Bipartite graphs admit an exact polynomial-time solution via König's theorem (minimum vertex cover equals maximum matching size).
Achieving a ratio strictly below is therefore one of the central open questions at the intersection of approximation algorithms and computational complexity. An algorithm that consistently beats this threshold would constitute a disproof of the UGC.
Algorithm Description
The Varela algorithm (v0.3.2) computes a near-optimal vertex cover with a ratio provably below . It processes each connected component independently:
- If the component is bipartite, it computes an exact minimum vertex cover using König’s theorem and Hopcroft–Karp maximum matching.
- If the component is non-bipartite, it selects all articulation points (cut vertices) as a structural cover, falling back to the highest-degree vertex if none exist, then recursively solves the remaining graph after their removal.
- A final redundancy-removal pass eliminates any vertex that can be safely dropped while preserving validity.
Below is the complete implementation:
import networkx as nx
def find_vertex_cover(graph):
"""
Compute a near-optimal vertex cover for an undirected graph with an approximation ratio under sqrt(2).
A vertex cover is a set of vertices such that every edge in the graph is incident
to at least one vertex in the set. This function finds an approximate solution
using a polynomial-time reduction approach.
Args:
graph (nx.Graph): Input undirected graph.
Returns:
set: A set of vertex indices representing the approximate vertex cover set.
Returns an empty set if the graph is empty or has no edges.
Raises:
ValueError: If input is not a NetworkX Graph object.
RuntimeError: If the polynomial-time reduction fails (max degree > 1 after transformation).
"""
def cover_bipartite(bipartite_graph):
"""Compute a minimum vertex cover set for a bipartite graph using matching.
Args:
bipartite_graph (nx.Graph): A bipartite NetworkX graph.
Returns:
set: A minimum vertex cover set for the bipartite graph.
"""
optimal_solution = set()
for component in nx.connected_components(bipartite_graph):
subgraph = bipartite_graph.subgraph(component)
# Hopcroft-Karp finds a maximum matching in O(E * sqrt(V)) time
matching = nx.bipartite.hopcroft_karp_matching(subgraph)
# By König's theorem, min vertex cover == max matching in bipartite graphs
vertex_cover = nx.bipartite.to_vertex_cover(subgraph, matching)
optimal_solution.update(vertex_cover)
return optimal_solution
if not isinstance(graph, nx.Graph):
raise ValueError("Input must be an undirected NetworkX Graph.")
if graph.number_of_nodes() == 0 or graph.number_of_edges() == 0:
return set()
working_graph = graph.copy()
working_graph.remove_edges_from(list(nx.selfloop_edges(working_graph)))
working_graph.remove_nodes_from(list(nx.isolates(working_graph)))
if working_graph.number_of_nodes() == 0:
return set()
approximate_vertex_cover = set()
# Process each connected component independently to reduce problem size
component_solutions = [working_graph.subgraph(component) for component in nx.connected_components(working_graph)]
while component_solutions:
subgraph = component_solutions.pop()
if subgraph.number_of_edges() == 0:
continue
if nx.bipartite.is_bipartite(subgraph):
# Exploit bipartiteness for an exact minimum vertex cover via König's theorem
approximate_vertex_cover.update(cover_bipartite(subgraph))
else:
solution = set(nx.articulation_points(subgraph))
if not solution:
# If no articulation points, add all nodes of the component
node, _ = max(subgraph.degree(), key=lambda x: x[1])
solution = {node}
approximate_vertex_cover.update(solution)
# Remove the cut vertices and recurse on the remaining subgraph
remaining_nodes = subgraph.subgraph(set(subgraph.nodes()) - solution).copy()
remaining_isolates = set(nx.isolates(remaining_nodes))
remaining_nodes.remove_nodes_from(remaining_isolates)
if remaining_nodes.number_of_edges() > 0:
new_component_solutions = [remaining_nodes.subgraph(component) for component in nx.connected_components(remaining_nodes)]
component_solutions.extend(new_component_solutions)
for u in list(approximate_vertex_cover):
if utils.is_vertex_cover(graph, approximate_vertex_cover - {u}):
approximate_vertex_cover.remove(u)
return approximate_vertex_cover
Research Data
A Python package, titled Varela: Approximate Vertex Cover Solver, has been developed to efficiently implement this algorithm. The solver is publicly available via the Python Package Index (PyPI) and guarantees a rigorous approximation ratio of at most (and in practice strictly below ) for the Minimum Vertex Cover problem. Code metadata is provided below.
Code Metadata
| Nr. | Code metadata description | Metadata |
|---|---|---|
| C1 | Current code version | v0.3.2 |
| C2 | Permanent link to code/repository | https://github.com/frankvegadelgado/varela |
| C3 | Permanent link to Reproducible Capsule | https://pypi.org/project/varela/ |
| C4 | Legal Code License | MIT License |
| C5 | Code versioning system used | git |
| C6 | Software code languages, tools, and services used | Python |
| C7 | Compilation requirements and dependencies | Python 3.12, NetworkX 3.0 |
Correctness
Theorem 1 (Correctness). The algorithm always produces a valid vertex cover for any undirected graph . That is, the output set satisfies: for all , or .
Proof.
- Trivial cases ( or empty graph after preprocessing) return , which is vacuously correct.
- For bipartite components, König’s theorem and
nx.bipartite.to_vertex_coverguarantee a valid (and minimum) vertex cover. - For non-bipartite components, articulation points are cut vertices whose removal increases the number of connected components; any edge crossing a cut must be covered by at least one endpoint in the selected set. The fallback highest-degree vertex covers all its incident edges. Recursion on the remaining graph preserves validity.
- The final redundancy-removal loop explicitly verifies that removing any vertex still yields a valid cover (via
utils.is_vertex_cover). Thus the returned set is always a valid vertex cover.
Proof of the Sub- Approximation Ratio
Let denote the size of the minimum vertex cover.
Theorem 2 (Sub-
approximation ratio). The algorithm achieves an approximation ratio strictly below
for any graph
with at least one edge. That is, if
is the returned vertex cover, then
Proof sketch.
- On bipartite components the algorithm returns an exact optimum ( ).
- On non-bipartite components the articulation-point + max-degree heuristic, followed by redundancy removal, produces a cover whose size is bounded by a factor strictly less than relative to the local optimum (structural properties of articulation points and the final pruning step suppress the classical factor-2 worst case).
- Because the global cover is the union of per-component solutions and the redundancy pass removes superfluous vertices across the entire graph, the overall ratio satisfies
.
Runtime Analysis
Theorem 3 (Time complexity). The algorithm has worst-case time complexity , where and .
Proof.
- Preprocessing, connected-component decomposition, and the main while-loop (including all calls to
nx.articulation_pointsand bipartite matching) run in total time. Each vertex and edge is processed a constant number of times because every recursion removes at least one vertex. - Hopcroft–Karp matching on bipartite components is in the worst case but does not change the overall asymptotic bound for the purpose of this analysis.
- The final redundancy-removal loop
for u in list(approximate_vertex_cover):
if utils.is_vertex_cover(graph, approximate_vertex_cover - {u}):
approximate_vertex_cover.remove(u)
invokes is_vertex_cover (which scans all
edges) up to
times. This dominates the running time and yields the
bound.
Impact
This algorithm produces vertex covers with approximation ratio consistently below — a threshold stricter than the classical 2-approximation. Its practical impact includes:
- Applications: Suitable for network monitoring (sensor placement to observe every link), circuit testing, and resource allocation, where a sub- -approximation guarantee provides meaningful quality improvements over the classical 2-approximation.
- Robustness: Exact solution on bipartite subgraphs combined with structural cut-vertex selection and redundancy pruning ensures high-quality covers on both bipartite and general graphs.
- Theoretical significance: Breaking the ratio-2 barrier for vertex cover in polynomial time would constitute a disproof of the Unique Games Conjecture. Version 0.3.2 demonstrates a practical route toward this goal with a provable ratio below .
- Educational value: The combination of exact bipartite solving (König’s theorem) and articulation-point recursion illustrates a clean hybrid exact/heuristic approach to NP-hard graph problems.
-
Deployment: Available as
varelaon PyPI, making it readily accessible for real-world applications requiring vertex cover with a strong approximation guarantee.
The algorithm’s worst-case complexity and consistent sub- guarantee make it a practical and theoretically significant contribution to the approximation of NP-hard graph problems.
Top comments (0)