Sub topic 3
Worked Reduction: Independent Set to Vertex Cover
This chapter assumes you know Python, Big-O notation, basic graph terms, and the definitions of P, NP, reductions, and NP-completeness from earlier chapters.
The Reduction
An independent set is a set of vertices with no edge between any two of them. A vertex cover is a set of vertices that touches every edge. In a graph with n vertices, S is independent exactly when its complement V − S is a vertex cover. So the instance (G, k) for Independent Set maps to the instance (G, n − k) for Vertex Cover. This mapping takes linear time.
def is_vertex_cover(edges, cover):
cover = set(cover)
return all(u in cover or v in cover for u, v in edges)
def is_independent_set(edges, subset):
subset = set(subset)
return not any(u in subset and v in subset for u, v in edges)
def independent_set_to_vertex_cover(vertices, edges, k):
return vertices, edges, len(vertices) - k
V, E = [1, 2, 3, 4], [(1, 2), (2, 3), (3, 4)]
S = {1, 3}
print(is_independent_set(E, S), is_vertex_cover(E, set(V) - S)) # True TrueOptimization Versus Decision
Asking for the largest independent set is an optimization problem. Asking "is there an independent set of size at least k?" is a decision problem. If you can solve the decision version, you can find the optimum by binary search on k. That is why classifying decision problems also tells you about optimization problems.
P vs NP
The P vs NP question asks whether every problem whose answers can be checked in polynomial time can also be solved in polynomial time. If P = NP, every NP-complete problem would have an efficient algorithm. That would break much of today's cryptography. If P ≠ NP, which most researchers expect, no NP-complete problem has a polynomial-time algorithm.
co-NP and NP-Intermediate
co-NP contains the problems whose "no" answers have short certificates that can be checked efficiently. UNSAT, which asks whether a formula has no satisfying assignment, is one example. Ladner's theorem says that if P ≠ NP, some NP problems are neither in P nor NP-complete. Graph isomorphism and integer factoring are the usual candidates.
Pseudo-Polynomial Time
For Subset Sum, dynamic programming runs in O(n · target) time. That bound is polynomial in the value of target but exponential in the number of bits needed to write target down. Problems that become easy when their numbers are small are called weakly NP-complete.
Handling NP-Hard Problems in Practice
- Approximation: taking both endpoints of every edge in a maximal matching gives a vertex cover at most twice the optimal size.
- Special cases: on trees, minimum vertex cover can be solved in linear time.
- Heuristics such as local search and simulated annealing.
- SAT and ILP solvers, which handle many large industrial instances well.
Exercise
A graph has 10 vertices and a vertex cover of size 6. What independent set size does that guarantee, and why?
Show answer
It guarantees an independent set of size 4. The complement of any vertex cover is an independent set, and 10 − 6 = 4.