Is an Approximation Algorithm for solving the Vertex Cover Problem.
Pseudocode
Takes as input an Undirected Graph and returns a vertex cover no more than twice the size of the optimal vertex cover.
def approx_vertex_cover(G: Graph) -> Set[int]:
# Initialize empty vertex cover
C: Set[int] = set()
# Make a copy of edges to work with
E_prime = edges.copy()
# While there are edges remaining
while len(E_prime > 0):
# Get an arbitrary edge from E'
u, v = next(iter(E_prime))
C.add(u)
C.add(v)
remove_incident_edges(u, v, E_prime)
return C
def remove_incident_edges(u, v, E):
for edge in E:
x, y = edge
if u in (x, y) or v in (x, y):
E -= edge
return ERuns in time.
Optimality
We have that approx_vertex_cover is a polynomial-time 2-approximation algorithm.
Proof
CLRS p. 1110.
Examples

(a) The input graph , which has 7 vertices and 8 edges.
(b) The edge , shown heavy, is the first edge chosen by approx_vertex_cover. Vertices and , shown lightly shaded, are added to the set containing the vertex cover being created. Edges , , and , shown dashed, are removed since they are now covered by some vertex in .
(c) Edge is chosen; vertices and are added to .
(d) Edge is chosen; vertices and are added to .
(e) The set , which is the vertex cover produced by approx_vertex_cover, contains the six vertices .
(f) The optimal vertex cover for this problem contains only three vertices: , and .