Sub topic 1
Problems, Instances, and Decision Versions
Prerequisites
This chapter assumes you know sets, functions, and graphs. It also assumes you can follow a short proof, recognize polynomial running time, and read basic Python.
Problems as Decision Problems
A problem is a family of questions. An instance is one specific question in that family, encoded as a string. A decision problem is a problem whose answer for every instance is yes or no. You can view it as a language: the set of encoded instances whose answer is yes.
Optimization problems become decision problems once you add a threshold. "Find the largest independent set" becomes "Does G have an independent set of size at least k?"
The Idea of a Reduction
A reduction from problem A to problem B converts any instance of A into an instance of B. You can then answer A by using any solver for B.
Many-One Reductions and Correctness
A many-one reduction is a computable function f such that x ∈ A if and only if f(x) ∈ B. A correctness proof has to cover both directions:
- If x is a yes-instance, then f(x) is a yes-instance.
- If f(x) is a yes-instance, then x is a yes-instance. You can also prove the contrapositive: no-instances map to no-instances.
A common mistake is to prove only the first direction.
Which Way Does It Go?
| You know | You conclude |
|---|---|
| B is easy and A reduces to B | A is easy |
| A is hard and A reduces to B | B is hard |
Algorithms transfer forward, from B to A. Hardness transfers backward, from A to B. If A reduces to B, then B is at least as hard as A.
First Examples: Independent Set, Vertex Cover, Clique
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. A set S is independent exactly when V − S is a vertex cover. So the reduction keeps the graph and changes only the bound.
def is_independent_set(edges, s):
return all(not (u in s and v in s) for u, v in edges)
def is_vertex_cover(edges, c):
return all(u in c or v in c for u, v in edges)
def independent_set_to_vertex_cover(vertices, edges, k):
# independent set of size >= k iff vertex cover of size <= |V| - k
return vertices, edges, len(vertices) - k
vertices = [1, 2, 3, 4]
edges = [(1, 2), (2, 3), (3, 4)]
s = {1, 3}
c = set(vertices) - s
assert is_independent_set(edges, s)
assert is_vertex_cover(edges, c)
print(independent_set_to_vertex_cover(vertices, edges, 2))Clique reduces to Independent Set in a similar way. Take the complement graph, which has an edge exactly where G has none. A k-clique in G is then a k-independent set in the complement.
Exercise
You reduce Independent Set to a new problem P in polynomial time. Independent Set is believed hard. What follows about P, and what would follow if you had instead reduced P to Independent Set?
Show answer
P is at least as hard as Independent Set, so P is believed hard too. A reduction from P to Independent Set would only show that P is no harder than Independent Set. It says nothing about whether P is hard.