Sub topic 14
The Primal-Dual Method
This chapter assumes you know linear programming (LP) basics, the LP relaxation of weighted vertex cover from the earlier chapter, and the idea of a dual LP. The rounding approach in that chapter solves the LP first. The primal-dual method skips the solver. It builds a feasible dual solution and an integer primal solution at the same time, and the dual solution certifies the approximation ratio.
Primal and Dual for Weighted Vertex Cover
The primal LP chooses fractional vertex values. The dual LP assigns a "payment" y_e to each edge.
| Row | Primal (cover) | Dual (packing) |
|---|---|---|
| Variables | `x_v >= 0` per vertex | `y_e >= 0` per edge |
| Objective | minimize `sum w_v x_v` | maximize `sum y_e` |
| Constraints | `x_u + x_v >= 1` for each edge `(u, v)` | `sum of y_e over edges at v <= w_v` for each vertex |
Weak duality states that every feasible dual value is at most the primal LP optimum. The primal LP optimum is in turn at most the integer optimum. So any feasible dual gives sum y_e <= OPT, and you get this lower bound without solving anything.
The Algorithm
Go through the edges in any order. When an edge is still uncovered, raise its dual y_e until one endpoint's constraint becomes tight, meaning the payments at that vertex equal its weight. Add every tight vertex to the cover.
def primal_dual_vertex_cover(n, edges, weights):
slack = list(weights)
cover = set()
y = {}
for u, v in edges:
if u in cover or v in cover:
continue
delta = min(slack[u], slack[v])
y[(u, v)] = delta
slack[u] -= delta
slack[v] -= delta
if slack[u] == 0:
cover.add(u)
if slack[v] == 0:
cover.add(v)
return cover, y
print(primal_dual_vertex_cover(4, [(0, 1), (1, 2), (2, 3)], [1, 3, 1, 2]))The output is ({0, 2}, {(0, 1): 1, (1, 2): 1}). The cover weighs 2 and the dual sums to 2, so this cover is optimal for this instance.
Why It Is a 2-Approximation
The dual stays feasible because no vertex's slack ever goes below zero. After an edge is processed, at least one of its endpoints is tight and in the cover, so the output covers every edge. Each cover vertex is tight, so its weight equals the payments of the edges at that vertex:
w(C) = sum over v in C of (sum of y_e at v) <= 2 * sum y_e <= 2 * OPT
The middle inequality holds because each edge has two endpoints, so it is counted at most twice.
Common Errors and Connections
- Raising duals past tightness. If you do this, the dual becomes infeasible and the lower bound is lost.
- Expecting the LP optimum. The dual you build is feasible but usually not optimal. The proof needs feasibility only.
- Dual fitting. Greedy set cover uses a related argument. Each element is charged a price, and dividing all prices by
H_ngives a feasible dual. This proves theH_nbound from that chapter.
Primal-dual algorithms are often faster than LP rounding, because they run in near-linear time and do not call a solver.
Exercise
Run the algorithm on the triangle edges [(0,1),(1,2),(0,2)] with weights [2,2,2]. What cover and dual sum do you get, and what does weak duality tell you about the optimum?
Show answer
Edge (0,1) gets y=2 and makes vertices 0 and 1 tight. Both enter the cover, and the other two edges are skipped. The cover {0,1} weighs 4 and the dual sum is 2, so OPT >= 2. The true optimum is 4 because any two vertices are needed, so the cover is optimal even though the dual certifies only the factor 2.