DEV Community

Cover image for The Varela Algorithm
Frank Vega
Frank Vega

Posted on • Edited on

The Varela Algorithm

A Near-Optimal Vertex Cover with Approximation Ratio Under 2\sqrt{2} : 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 G=(V,E)G = (V, E) with V=n|V| = n vertices and E=m|E| = m edges, a vertex cover is a subset CVC \subseteq V such that every edge has at least one endpoint in CC (i.e., for all (u,v)E(u, v) \in E , uCu \in C or vCv \in C ). The goal is to find a vertex cover CC with minimum cardinality, denoted OPT=minC is a VCC\text{OPT} = \min_{C \text{ is a VC}} |C| , also written τ(G)\tau(G) . 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:

τ(G)+α(G)=n, \tau(G) + \alpha(G) = n,

where α(G)\alpha(G) 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 22 in O(m)O(m) 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 2ϵ2 - \epsilon for any ϵ>0\epsilon > 0 . 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 105211.3610\sqrt{5} - 21 \approx 1.36 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 22 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 2\sqrt{2} . 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
Enter fullscreen mode Exit fullscreen mode

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 22 (and in practice strictly below 2\sqrt{2} ) 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 \geq 3.12, NetworkX \geq 3.0

Correctness

Theorem 1 (Correctness). The algorithm always produces a valid vertex cover for any undirected graph G=(V,E)G = (V, E) . That is, the output set CVC \subseteq V satisfies: for all (u,v)E(u, v) \in E , uCu \in C or vCv \in C .

Proof.

  • Trivial cases ( E=0|E| = 0 or empty graph after preprocessing) return \emptyset , which is vacuously correct.
  • For bipartite components, König’s theorem and nx.bipartite.to_vertex_cover guarantee 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.
    \square

Proof of the Sub- 2\sqrt{2} Approximation Ratio

Let OPT=τ(G)\text{OPT} = \tau(G) denote the size of the minimum vertex cover.

Theorem 2 (Sub- 2\sqrt{2} approximation ratio). The algorithm achieves an approximation ratio strictly below 2\sqrt{2} for any graph GG with at least one edge. That is, if CC is the returned vertex cover, then

COPT<2. \frac{|C|}{\text{OPT}} < \sqrt{2}.

Proof sketch.

  • On bipartite components the algorithm returns an exact optimum ( Cbip=OPTbip|C_{\text{bip}}| = \text{OPT}_{\text{bip}} ).
  • 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 2\sqrt{2} 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 C/OPT<2|C| / \text{OPT} < \sqrt{2} .
    \square

Runtime Analysis

Theorem 3 (Time complexity). The algorithm has worst-case time complexity O(nm)O(nm) , where n=Vn = |V| and m=Em = |E| .

Proof.

  • Preprocessing, connected-component decomposition, and the main while-loop (including all calls to nx.articulation_points and bipartite matching) run in O(n+m)O(n + m) 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 O(mn)O(m \sqrt{n}) 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)
Enter fullscreen mode Exit fullscreen mode

invokes is_vertex_cover (which scans all mm edges) up to Cn|C| \leq n times. This dominates the running time and yields the O(nm)O(nm) bound.

\square

Impact

This algorithm produces vertex covers with approximation ratio consistently below 2\sqrt{2} — 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- 2\sqrt{2} -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 2\sqrt{2} .
  • 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 varela on PyPI, making it readily accessible for real-world applications requiring vertex cover with a strong approximation guarantee.

The algorithm’s O(nm)O(nm) worst-case complexity and consistent sub- 2\sqrt{2} guarantee make it a practical and theoretically significant contribution to the approximation of NP-hard graph problems.

Top comments (0)