← Course home

Advanced applications · Lesson 52 of 52

Approximation guarantees

Prove feasibility and a factor-two bound for a vertex-cover construction.

Full lessonAbout 10 min

You will learn to prove the constructed set is a vertex cover and derive the factor-two approximation guarantee.

Recommended first: Greedy methods.

On this page 6 sections

The idea

Two disjoint edges produce a cover of 4 endpoints. An optimum cover has size 2.

Some problems have no known exact algorithm that is fast on every input. An approximation algorithm returns a legal answer whose cost is provably close to the best cost. vertex_cover_two_approximation scans edges and, when neither endpoint is already chosen, adds both. On a graph with only the edges A-B and C-D, the cover is the set A, B, C, D. The cover is feasible because every edge has both ends selected, so it certainly has one. An optimum cover can pick one end from each edge, so its size is 2. The algorithm returned 4, which is twice the optimum. The proof is the pairing. Each time the algorithm adds two vertices, it does so for an edge whose ends were both still free. Those edges do not share vertices. Any cover must pick at least one vertex from each such edge. The algorithm picked two. The ratio is therefore at most 2 on every graph, not only on this one.

A worked trace

StepStateWhat changed
startcover = []The cover starts empty. No edge has been scanned.
paircover = ['A', 'B']The edge A to B adds both ends.
paircover = ['A', 'B', 'C', 'D']The edge C to D adds both ends.

Why it is correct

Feasibility is the first half. Every edge is either selected as a pair or already touched by an earlier pair, so no edge is left uncovered. The ratio is the second half. Let the selected edges be the ones that contributed a pair. They are vertex-disjoint, so the optimum is at least the number of those edges. The algorithm's cover has two vertices per selected edge, plus nothing else from this rule. Twice the optimum is therefore an upper bound on the size of the cover. A single example that happens to be close is not this proof. The proof counts the disjoint edges.

A common mistake

A cover that happens to look small on one graph is not the ratio proof.

What it costs

The scan looks at each adjacency-list entry once, so the time is proportional to vertices plus edges. Extra memory is the cover set, which is at most the vertices. The guarantee does not say the cover is the smallest possible. It says you can bound how far it is from the smallest. Use that bound when an exact cover would require a search you cannot afford. The scan is Θ(V + E) time, and the cover uses O(V) extra memory.

Run it

python
from bitsandbytes.limits.approximation import vertex_cover_two_approximationfrom bitsandbytes.graphs.adjacency_list import Graphgraph = Graph()graph.add_edge('A', 'B', 1)graph.add_edge('C', 'D', 1)print(sorted(vertex_cover_two_approximation(graph)))# prints: ['A', 'B', 'C', 'D'] 

Practice and next step

Open Analysis and library costs next.

Implementation and tests Optional reference

Library code 1

  • bitsandbytes.limits.approximation

Use these references to compare the explanation with repository code and tests. A test link means it imports a lesson symbol; it does not by itself claim complete behavior coverage.

Step-by-step trace

A vertex cover at most twice the optimum

Two disjoint edges produce a cover of all four endpoints. The optimum picks one endpoint from each edge. The constructed cover is twice that size.

cover
[]

State

  1. 0-chosen

The cover starts empty. No edge has been scanned.

Practice feedback is loading. The lesson explanation remains available above.