Min Vertex Cover Visualization

Watch greedy approximation and weighted pricing algorithms find minimum vertex covers on random graphs step by step.

Nodes8
hub

Generate a graph to visualize vertex cover algorithms

Algorithm: Edge-Picking 2-ApproxCover size: 0Edges covered: 0/0Nodes in cover: 0/0

Generate a graph to get started.

What is a Vertex Cover?

A vertex cover of a graph is a set of vertices such that every edge has at least one endpoint in the set. The minimum vertex cover is the smallest such set.

This is one of Karp's 21 NP-complete problems, meaning no polynomial-time exact algorithm is known. However, there are efficient approximation algorithms that guarantee solutions within a factor of 2 of optimal.

Algorithms

Edge-Picking 2-Approximation

Pick any uncovered edge, add both endpoints to the cover, remove all edges incident to those vertices. Repeat until no uncovered edges remain. This gives a cover at most 2x the optimal size. The algorithm runs in O(V + E) time and is the simplest known approximation with a provable guarantee.

Weighted Greedy (Best Ratio)

When vertices have weights, a pure edge-picking approach ignores costs. Instead, at each step pick the vertex with the best ratio of uncovered edges per unit weight. Add it to the cover and remove all its incident edges. This heuristic tends to produce good weighted covers in practice.

Vertex Cover vs Related Problems

ProblemGoalComplexity
Min Vertex CoverFewest vertices covering all edgesNP-hard (2-approx exists)
Max Independent SetLargest set with no edges betweenNP-hard (complement of VC)
Min Dominating SetFewest vertices within 1 hop of allNP-hard (no constant approx)
Min Edge CoverFewest edges covering all verticesPolynomial (matching-based)

Frequently Asked Questions

What is a vertex cover?add

A vertex cover of a graph is a set of vertices such that every edge in the graph has at least one endpoint in the set. The minimum vertex cover problem asks for the smallest such set. It is one of the classic NP-hard problems in computer science.

What is the difference between vertex cover and independent set?add

A vertex cover and an independent set are complements. If S is a vertex cover, then V - S (all vertices not in S) is an independent set, and vice versa. Finding the minimum vertex cover is equivalent to finding the maximum independent set. Both problems are NP-hard.

What is the 2-approximation for vertex cover?add

The edge-picking algorithm provides a 2-approximation: repeatedly pick any uncovered edge, add both endpoints to the cover, and remove all edges incident to those vertices. This runs in O(V + E) time and guarantees a cover at most twice the size of the optimal. No better polynomial-time approximation is known unless P = NP.

What is a weighted vertex cover?add

In the weighted version, each vertex has a cost/weight, and the goal is to find a vertex cover with minimum total weight. The greedy approach picks vertices with the best ratio of uncovered edges per unit weight. The pricing (LP relaxation) method provides a 2-approximation for the weighted case as well.

Where are vertex cover problems used in practice?add

Vertex cover appears in network security (monitoring all connections with minimum sensors), bioinformatics (identifying key genes in interaction networks), VLSI design, and scheduling problems. The concept of covering all edges with minimum resources is fundamental in optimization.

apartment

Company Interview Questions

See which problems Google, Meta, Amazon, and 200+ companies actually ask in real interviews.

Browse questions arrow_forward

Can you explain NP-hardness and approximation algorithms?

Understanding why vertex cover is NP-hard and how the 2-approximation works is a common interview topic. Practice explaining it under pressure.

Try a free mock interview arrow_forward