The algorithm presented in the preceding section runs in polynomial time, and we have seen that it outputs a vertex cover whose weight is at most twice the weight of the optimum vertex cover, a fact that we express by saying that its approximation factor is .
However, the algorithm needs to solve a linear program and although this can be done in polynomial time, there are much faster ways to compute a vertex cover with approximation factor 2 without solving the linear program. One such algorithm, that we present in this section, is a primal-dual approximation algorithm, meaning that it makes choices guided by the linear program () and its dual but does not actually solve them to optimality.
Let us write the linear programming relaxation of weighted vertex cover once again, along with its dual.
And, its dual is given as,
Here, the notation denotes the set of all edges having as an endpoint. One may interpret the dual variable as prices associated to the edges, and one may interpret as the wealth of vertex . The dual constraint asserts that has enough wealth to pay for all of the edges incident to it. If edge prices satisfy all the constraints of () then every vertex has enough wealth to pay for its incident edges, and consequently every vertex set has enough combined wealth to pay for all of the edges covered by . In particular, if is a vertex cover then the combined wealth of the vertices in must be at least , which is a manifestation of weak duality: the optimum value of the dual is a lower bound on the optimum value of the primal .
The dual LP insists that we maximize the combined price of all edges, subject to the constraint that each vertex has enough wealth to pay for all the edges it covers. Rather than exactly maximizing the combined price of all edges, we will set edge prices using a natural (but suboptimal) greedy heuristic: go through the edges in arbitrary order, increasing the price of each one as much as possible without violating the dual constraints. This results in the following algorithm.
The variables keep track of the sum (i.e., the left-hand side of the dual constraint corresponding to vertex ) as it grows during the execution of the algorithm. The rule for updating by inserting each vertex such that is inspired by the principle of complementary slackness from the theory of linear programming duality: if is an optimal solution of a primal linear program and is an optimal solution of the dual, then for every such that the th dual constraint must be satisfied with equality by ; similarly, for every such that , the th primal constraint is satisfied with equality by . Thus, it is natural that our decisions of which vertices to include in our vertex cover (primal solution) should be guided by keeping track of which dual constraints are tight .
It is clear that each iteration of the main loop runs in constant time, so the algorithm runs in linear time. At the end of the loop processing edge , at least one of the vertices must belong to . Therefore, is a vertex cover. To conclude the analysis we need to prove that the approximation factor is 2. To do so, we note the following loop invariants - statements that hold at the beginning and end of each execution of the for loop, though not necessarily in the middle. Each of them is easily proven by induction on the number of iterations of the for loop.
Now the proof of the approximation factor is easy. Recalling that by week duality, we find that:
(8.4) |