8. INTRACTABILITY I
‣ poly-time reductions
‣ packing and covering problems ‣ constraint satisfaction problems ‣ sequencing problems
‣ partitioning problems
‣ graph coloring
‣ numerical problems
Lecture slides by Kevin Wayne
Copyright © 2005 Pearson-Addison Wesley
http://www.cs.princeton.edu/~wayne/kleinberg-tardos
Last updated on 2/25/20 3:57 PM
SECTION 8.1
8. INTRACTABILITY I
‣ poly-time reductions
‣ packing and covering problems ‣ constraint satisfaction problems ‣ sequencing problems
‣ partitioning problems
‣ graph coloring
‣ numerical problems
Algorithm design patterns and antipatterns
Algorithm design patterns.
・Greedy.
・Divide and conquer. ・Dynamic programming. ・Duality.
・Reductions.
・Local search. ・Randomization.
Algorithm design antipatterns.
・NP-completeness. ・PSPACE-completeness. ・Undecidability.
O(nk) algorithm unlikely.
O(nk) certification algorithm unlikely. No algorithm possible.
3
Classify problems according to computational requirements
Q. Which problems will we be able to solve in practice? A working definition. Those with poly-time algorithms.
von Neumann Nash Gödel Cobham Edmonds Rabin (1953) (1955) (1956) (1964) (1965) (1966)
Turing machine, word RAM, uniform circuits, …
Theory. Definition is broad and robust.
constants tend to be small, e.g., 3 n 2 Practice. Poly-time algorithms scale to huge problems.
4
Classify problems according to computational requirements
Q. Which problems will we be able to solve in practice? A working definition. Those with poly-time algorithms.
yes
probably no
shortest path
longest path
min cut
max cut
2-satisfiability
3-satisfiability
planar 4-colorability
planar 3-colorability
bipartite vertex cover
vertex cover
matching
3d-matching
primality testing
factoring
linear programming
integer linear programming
5
Classify problems
Desiderata. Classify problems according to those that can be solved in polynomial time and those that cannot.
input size = c + log k
Provably requires exponential time.
・Given a constant-size program, does it halt in at most k steps? ・Given a board position in an n-by-n generalization of checkers,
can black guarantee a win?
using forced capture rule
Frustrating news. Huge number of fundamental problems have defied classification for decades.
6
Poly-time reductions
Desiderata′. Suppose we could solve problem Y in polynomial time. What else could we solve in polynomial time?
Reduction. Problem X polynomial-time (Cook) reduces to problem Y if a・rbitrary instances of problem X can be solved using:
・Polynomial number of standard computational steps, plus Polynomial number of calls to oracle that solves problem Y.
computational model supplemented by special piece of hardware that solves instances of Y in a single step
Algorithm
for Y
instance I
(of X)
solution S to I
Algorithm for X
7
Poly-time reductions
Desiderata′. Suppose we could solve problem Y in polynomial time. What else could we solve in polynomial time?
Reduction. Problem X polynomial-time (Cook) reduces to problem Y if arbitrary instances of problem X can be solved using:
・Polynomial number of standard computational steps, plus ・Polynomial number of calls to oracle that solves problem Y.
Notation. X ≤ P Y.
Note. We pay for time to write down instances of Y sent to oracle ⇒
instances of Y must be of polynomial size. Novice mistake. Confusing X ≤ P Y with Y ≤ P X.
8
Intractability: quiz 1
Suppose that X ≤ P Y. Which of the following can we infer?
A. If X can be solved in polynomial time, then so can Y.
B. X can be solved in poly time iff Y can be solved in poly time.
C. If X cannot be solved in polynomial time, then neither can Y.
D. If Y cannot be solved in polynomial time, then neither can X.
9
Intractability: quiz 2
Which of the following poly-time reductions are known?
A. FIND-MAX-FLOW ≤ P FIND-MIN-CUT.
O(mn2) time: Dinitz’ algorithm O(m) time: given max flow f,
let A = set of nodes reachable from s in Gf
B. FIND-MIN-CUT ≤ P
C. Both A and B.
D. Neither A nor B.
FIND-MAX-FLOW.
10
Poly-time reductions
Design algorithms. If X ≤ P Y and Y can be solved in polynomial time, then X can be solved in polynomial time.
Establish intractability. If X ≤ P Y and X cannot be solved in polynomial time, then Y cannot be solved in polynomial time.
Establish equivalence. If both X ≤P Y and Y ≤P X, we use notation X ≡P Y. In this case, X can be solved in polynomial time iff Y can be.
Bottom line. Reductions classify problems according to relative difficulty.
11
SECTION 8.1
8. INTRACTABILITY I
‣ poly-time reductions
‣ packing and covering problems ‣ constraint satisfaction problems ‣ sequencing problems
‣ partitioning problems
‣ graph coloring
‣ numerical problems
Independent set
INDEPENDENT-SET. Given a graph G = (V, E) and an integer k, is there a subset of k (or more) vertices such that no two are adjacent?
Ex. Is there an independent set of size ≥ 6 ? Ex. Is there an independent set of size ≥ 7 ?
independent set of size 6
13
Vertex cover
VERTEX-COVER. Given a graph G = (V, E) and an integer k, is there a subset of k (or fewer) vertices such that each edge is incident to at least one vertex in the subset?
Ex. Is there a vertex cover of size ≤ 4 ? Ex. Is there a vertex cover of size ≤ 3 ?
independent set of size 6 vertex cover of size 4
14
Intractability: quiz 3
Consider the following graph G. Which are true?
A. The white vertices are a vertex cover of size 7.
B. The black vertices are an independent set of size 3.
C. Both A and B.
D. Neither A nor B.
15
Vertex cover and independent set reduce to one another
Theorem. INDEPENDENT-SET ≡ P VERTEX-COVER.
Pf. We show S is an independent set of size k iff V − S is a vertex cover of size n – k.
independent set of size 6 vertex cover of size 4
16
Vertex cover and independent set reduce to one another
Theorem. INDEPENDENT-SET ≡ P VERTEX-COVER.
Pf. We show S is an independent set of size k iff V − S is a vertex cover of size n – k.
⇒・Let S be any independent set of size k.
・V − S is of size n – k.
・Consider an arbitrary edge (u, v) ∈ E.
・S independent ⇒ either u ∉ S, or v ∉ S, or both.
⇒ either u ∈ V − S, or v ∈ V − S, or both. ・Thus, V − S covers (u, v). ▪
17
Vertex cover and independent set reduce to one another
Theorem. INDEPENDENT-SET ≡ P VERTEX-COVER.
Pf. We show S is an independent set of size k iff V − S is a vertex cover of size n – k.
⇐・Let V − S be any vertex cover of size n – k.
・S is of size k.
・Consider an arbitrary edge (u, v) ∈ E.
・V − S is a vertex cover ⇒ either u ∈ V − S, or v ∈ V − S, or both.
⇒ either u ∉ S, or v ∉ S, or both. ・Thus, S is an independent set. ▪
18
Set cover
SET-COVER. Given a set U of elements, a collection S of subsets of U, and an integer k, are there ≤ k of these subsets whose union is equal to U ?
Sample application.
・m available pieces of software.
・Set U of n capabilities that we would like our system to have. ・The ith piece of software provides the set Si ⊆ U of capabilities. ・Goal: achieve all n capabilities using fewest pieces of software.
U = { 1, 2, 3, 4, 5, 6, 7 }
Sa = { 3, 7 }
Sc = { 3, 4, 5, 6 } Se = { 1 }
k= 2
Sb = { 2, 4 }
Sd = { 5 }
Sf = { 1, 2, 6, 7 }
a set cover instance
19
Intractability: quiz 4
Given the universe U = { 1, 2, 3, 4, 5, 6, 7 } and the following sets, which is the minimum size of a set cover?
A. 1
B. 2
C. 3
D. None of the above.
U = { 1, 2, 3, 4, 5, 6, 7 }
Sa = { 1, 4, 6 } Sc = { 1, 2, 3, 6 } Se = { 2, 6, 7 }
Sb = { 1, 6, 7 } Sd = { 1, 3, 5, 7 }
Sf = { 3, 4, 5 }
20
Vertex cover reduces to set cover
Theorem. VERTEX-COVER ≤ P SET-COVER.
Pf. Given a VERTEX-COVER instance G = (V, E) and k, we construct a SET-COVER instance (U, S, k) that has a set cover of size k iff G has a vertex cover of size k.
C・onstruction. ・Universe U = E.
Include one subset for each node v ∈ V : Sv = {e ∈ E : e incident to v }.
a
e7 e2 e3 e4
f e6 c
e5 ed
vertex cover instance (k = 2)
b
U = { 1, 2, 3, 4, 5, 6, 7 }
Sa = { 3, 7 }
Sc = { 3, 4, 5, 6 } Se = { 1 }
Sb = { 2, 4 }
Sd = { 5 }
Sf = { 1, 2, 6, 7 }
e1
set cover instance (k = 2)
21
Vertex cover reduces to set cover
Lemma. G = (V, E) contains a vertex cover of size k iff (U, S, k) contains a set cover of size k.
P・f. ⇒ Let X ⊆ V be a vertex cover of size k in G. Then Y = { Sv : v ∈ X } is a set cover of size k. ▪
“yes” instances of VERTEX-COVER are solved correctly
a
e7 e2 e3 e4
e6
b
U = { 1, 2, 3, 4, 5, 6, 7 }
Sa = { 3, 7 }
Sc = { 3, 4, 5, 6 } Se = { 1 }
Sb = { 2, 4 }
Sd = { 5 }
Sf = { 1, 2, 6, 7 }
f
c
e1
e5 ed
vertex cover instance (k = 2)
set cover instance (k = 2)
22
Vertex cover reduces to set cover
Lemma. G = (V, E) contains a vertex cover of size k iff (U, S, k) contains a set cover of size k.
P・f. ⇐ Let Y ⊆ S be a set cover of size k in (U, S, k). Then X = { v : Sv ∈ Y } is a vertex cover of size k in G.
▪
“no” instances of VERTEX-COVER are solved correctly
a
e7 e2 e3 e4
e6
b
U = { 1, 2, 3, 4, 5, 6, 7 }
Sa = { 3, 7 }
Sc = { 3, 4, 5, 6 } Se = { 1 }
Sb = { 2, 4 }
Sd = { 5 }
Sf = { 1, 2, 6, 7 }
f
c
e1
e5 ed
vertex cover instance (k = 2)
set cover instance (k = 2)
23
SECTION 8.2
8. INTRACTABILITY I
‣ poly-time reductions
‣ packing and covering problems ‣ constraint satisfaction problems ‣ sequencing problems
‣ partitioning problems
‣ graph coloring
‣ numerical problems
Satisfiability
Literal. A Boolean variable or its negation. Clause. A disjunction of literals.
€
xi or xi
Cj =x1 ∨x2 ∨x3
Conjunctive normal form (CNF). A propositional
Φ= C1∧C2∧C3∧C4 SAT. Given a CNF formula Φ, does it have a satisfying truth assignment?
formula Φ that is a conjunction of clauses.
€
3-SAT. SAT where each clause contains exactly 3 literals (and each literal corresponds to a different variable).
yes instance: x1 = true, x2 = true, x3 = false, x4 = false
€
Key application. Electronic design automation (EDA).
€
Φ =(x1 ∨x2 ∨x3)∧(x1 ∨x2 ∨x3)∧(x1 ∨x2 ∨x4)
25
Satisfiability is hard
Scientific hypothesis. There does not exist a poly-time algorithm for 3-SAT. P vs. NP. This hypothesis is equivalent to P ≠ NP conjecture.
https://www.facebook.com/pg/npcompleteteens
26
3-satisfiability reduces to independent set
Theorem. 3-SAT ≤ P INDEPENDENT-SET.
Pf. Given an instance Φ of 3-SAT, we construct an instance (G, k) of INDEPENDENT-SET that has an independent set of size k = ⎜Φ ⎜ iff Φ is satisfiable.
C・onstruction.
・G contains 3 nodes for each clause, one for each literal. ・Connect 3 literals in a clause in a triangle.
Connect literal to each of its negations.
G
k=3
Φ =(x1 ∨x2 ∨x3)∧(x1 ∨x2 ∨x3)∧(x1 ∨x2 ∨x4)
27
3-satisfiability reduces to independent set
Lemma. Φ is satisfiable iff G contains an independent set of size k = ⎜Φ⎜.
P・f. ⇒ Consider any satisfying assignment for Φ. ・Select one true literal from each clause/triangle.
This is an independent set of size k = ⎜Φ⎜. ▪
“yes” instances of 3-SAT are solved correctly
G
k=3
Φ =(x1 ∨x2 ∨x3)∧(x1 ∨x2 ∨x3)∧(x1 ∨x2 ∨x4)
28
3-satisfiability reduces to independent set
Lemma. Φ is satisfiable iff G contains an independent set of size k = ⎜Φ⎜.
P・f. ⇐ Let S be independent set of size k.
・S must contain exactly one node in each triangle.
・Set these literals to true (and remaining literals consistently).
All clauses in Φ are satisfied. ▪
“no” instances of 3-SAT are solved correctly
G
k=3
Φ =(x1 ∨x2 ∨x3)∧(x1 ∨x2 ∨x3)∧(x1 ∨x2 ∨x4)
29
Review
Basic reduction strategies.
・Simple equivalence: INDEPENDENT-SET ≡ P VERTEX-COVER. ・Special case to general case: VERTEX-COVER ≤ P SET-COVER. ・Encoding with gadgets: 3-SAT ≤ P INDEPENDENT-SET.
Transitivity. If X ≤ P Y and Y ≤ P Z, then X ≤ P Z. Pf idea. Compose the two algorithms.
Ex. 3-SAT ≤ P INDEPENDENT-SET ≤ P VERTEX-COVER ≤ P SET-COVER.
30
DECISION, SEARCH, AND OPTIMIZATION PROBLEMS
Decision problem. Does there exist a vertex cover of size ≤ k ? Search problem. Find a vertex cover of size ≤ k.
Optimization problem. Find a vertex cover of minimum size.
Goal. Show that all three problems poly-time reduce to one another.
31
SEARCH PROBLEMS VS. DECISION PROBLEMS
VERTEX-COVER. Does there exist a vertex cover of size ≤ k ? FIND-VERTEX-COVER. Find a vertex cover of size ≤ k.
Theorem. VERTEX-COVER ≡ P FIND-VERTEX-COVER.
Pf. ≤ P Decision problem is a special case of search problem. ▪
Pf. ≥P
T・o find a vertex cover of size ≤ k :
・Determine if there exists a vertex cover of size ≤ k.
Find a vertex v such that G − { v } has a vertex cover of size ≤ k − 1.
・(any vertex in any vertex cover of size ≤ k will have this property) ・Include v in the vertex cover.
Recursively find a vertex cover of size ≤ k − 1 in G − {v}. ▪
delete v and all incident edges 32
OPTIMIZATION PROBLEMS VS. SEARCH PROBLEMS
FIND-VERTEX-COVER. Find a vertex cover of size ≤ k. FIND-MIN-VERTEX-COVER. Find a vertex cover of minimum size.
Theorem. FIND-VERTEX-COVER ≡ P FIND-MIN-VERTEX-COVER.
Pf. ≤ P Search problem is a special case of optimization problem. ▪
P・f. ≥ P To find vertex cover of minimum size:
・Binary search (or linear search) for size k* of min vertex cover.
Solve search problem for given k*. ▪
33
SECTION 8.5
8. INTRACTABILITY I
‣ poly-time reductions
‣ packing and covering problems ‣ constraint satisfaction problems ‣ sequencing problems
‣ partitioning problems
‣ graph coloring
‣ numerical problems
Hamilton cycle
HAMILTON-CYCLE. Given an undirected graph G = (V, E), does there exist a cycle Γ that visits every node exactly once?
yes
35
Hamilton cycle
HAMILTON-CYCLE. Given an undirected graph G = (V, E), does there exist a cycle Γ that visits every node exactly once?
1
2
3
4
5
1ʹ
2ʹ
3ʹ
4ʹ
no
36
Directed Hamilton cycle reduces to Hamilton cycle
DIRECTED-HAMILTON-CYCLE. Given a directed graph G = (V, E), does there exist a directed cycle Γ that visits every node exactly once?
Theorem. DIRECTED-HAMILTON-CYCLE ≤ P HAMILTON-CYCLE.
Pf. Given a directed graph G = (V, E), construct a graph Gʹ with 3n nodes.
aout
bout vin v vout
a
bv c
directed graph G
d e
din
ein
cout
undirected graph G′
37
Directed Hamilton cycle reduces to Hamilton cycle
Lemma. G has a directed Hamilton cycle iff Gʹ has a Hamilton cycle.
Pf. ⇒
・Suppose G has a directed Hamilton cycle Γ.
・Then Gʹ has an undirected Hamilton cycle (same order). ▪
Pf. ⇐
・Suppose Gʹ has an undirected Hamilton cycle Γʹ.
・Γʹ must visit nodes in Gʹ using one of following two orders:
…, black, white, blue, black, white, blue, black, white, blue, … ・ …, black, blue, white, black, blue, white, black, blue, white, …
Black nodes in Γʹ comprise either a directed Hamilton cycle Γ in G, or reverse of one. ▪
38
3-satisfiability reduces to directed Hamilton cycle
Theorem. 3-SAT ≤ P DIRECTED-HAMILTON-CYCLE.
Pf. Given an instance Φ of 3-SAT, we construct an instance G of
DIRECTED-HAMILTON-CYCLE that has a Hamilton cycle iff Φ is satisfiable.
Construction overview. Let n denote the number of variables in Φ.
We will construct a graph G that has 2n Hamilton cycles, with each cycle corresponding to one of the 2n possible truth assignments.
39
3-satisfiability reduces to directed Hamilton cycle
C・onstruction. Given 3-SAT instance Φ with n variables xi and k clauses.
・Construct G to have 2n Hamilton cycles.
Intuition: traverse path i from left to right ⇔ set variable x = true. i
s
x1
x2
x3
t
40
Intractability: quiz 5
Which is truth assignment corresponding to Hamilton cycle below?
A. x1=true,x2=true,x3=true B. x1=true,x2=true,x3=false
C. x1=false,x2=false,x3=true D. x1=false,x2=false,x3=false
s
x1
x2
x3
t
41
3-satisfiability reduces to directed Hamilton cycle
C・onstruction. Given 3-SAT instance Φ with n variables xi and k clauses. For each clause: add a node and 2 edges per literal.
node for clause j
node for clause k
connect in this way
if xi appears in clause Cj
connect in this way
if xi appears in clause Ck
xi
Cj
Ck
xi = true
xi = false
42
3-satisfiability reduces to directed Hamilton cycle
C・onstruction. Given 3-SAT instance Φ with n variables xi and k clauses. For each clause: add a node and 2 edges per literal.
C1 =x1 x2 x3
clausenode1
clausenode2
C2 =x1 x2 x3
x1
x2
x3
s
t
3k + 3
43
3-satisfiability reduces to directed Hamilton cycle
Lemma. Φ is satisfiable iff G has a Hamilton cycle.
P・f. ⇒
・Suppose 3-SAT instance Φ has satisfying assignment x*.
Then, define Hamilton cycle Γ in G as follows:
– – –
if x*i = true, traverse row i from left to right
if x*i = false, traverse row i from right to left
for each clause Cj , there will be at least one row i in which we are going in “correct” direction to splice clause node Cj into cycle (and we splice in Cj exactly once) ▪
44
3-satisfiability reduces to directed Hamilton cycle
Lemma. Φ is satisfiable iff G has a Hamilton cycle.
Pf. ⇐
・Suppose G has a Hamilton cycle Γ.
・If Γ enters clause node Cj , it must depart on mate edge.
– –
Continuing in this way, we are left with a Hamilton cycle Γʹ in
・G – { C1 , C2 , …, Ck }.
・Set x* = true if Γʹ traverses row i left-to-right; otherwise, set x* = false. ii
traversed in “correct” direction, and each clause is satisfied. ▪
nodes immediately before and after Cj are connected by an edge e ∈ E
removing Cj from cycle, and replacing it with edge e yields Hamilton ・ cycle on G – { Cj }
45
Poly-time reductions
constraint satisfaction
3-SAT
INDEPENDENT-SET
VERTEX-COVER
SET-COVER
packing and covering
DIR-HAM-CYCLE
HAM-CYCLE
3-COLOR
SUBSET-SUM
KNAPSACK
sequencing
partitioning
numerical
46
3-SAT poly-time reduces to INDEPENDENT-SET
SECTION 8.6
8. INTRACTABILITY I
‣ poly-time reductions
‣ packing and covering problems ‣ constraint satisfaction problems ‣ sequencing problems
‣ partitioning problems
‣ graph coloring
‣ numerical problems
3-dimensional matching
3D-MATCHING. Given n instructors, n courses, and n times, and a list of the possible courses and times each instructor is willing to teach, is it possible to make an assignment so that all courses are taught at different times?
instructor
course
time
Wayne
COS 226
TTh 11–12:20
Wayne
COS 423
MW 11–12:20
Wayne COS 423 TTh 11–12:20
Tardos
COS 423
TTh 3–4:20
Tardos COS 523 TTh 3–4:20
Kleinberg
COS 226
TTh 3–4:20
Kleinberg COS 226 MW 11–12:20
Kleinberg
COS 423
MW 11–12:20
48
3-dimensional matching
3D-MATCHING. Given 3 disjoint sets X, Y, and Z, each of size n and a set T ⊆ X × Y × Z of triples, does there exist a set of n triples in T such that each element of X ∪ Y ∪ Z is in exactly one of these triples?
X = { x1, x2, x3 }, T1 = { x1, y1, z2 },
T4 = { x2, y2, z3 }, T7 = { x3, y1, z3 },
Y = { y1, y2, y3 }, T2 = { x1, y2, z1 },
T5 = { x2, y3, z3 }, T8 = { x3, y1, z1 },
Z = { z1, z2, z3 } T3 = { x1, y2, z2 }
T9 = { x3, y2, z1 }
an instance of 3d-matching (with n = 3)
Remark. Generalization of bipartite matching.
49
3-dimensional matching
3D-MATCHING. Given 3 disjoint sets X, Y, and Z, each of size n and a set T ⊆ X × Y × Z of triples, does there exist a set of n triples in T such that each element of X ∪ Y ∪ Z is in exactly one of these triples?
Theorem. 3-SAT ≤ P 3D-MATCHING.
Pf. Given an instance Φ of 3-SAT, we construct an instance of 3D-MATCHING that has a perfect matching iff Φ is satisfiable.
50
3-satisfiability reduces to 3-dimensional matching
C・onstruction. (part 1)
Create gadget for each variable xi with 2k core elements and 2k tip ones.
number of clauses
clause 2 tips
clause 1 tips
core elements
clause 3 tips
a gadget for variable xi (k = 4)
51
3-satisfiability reduces to 3-dimensional matching
number of clauses
In gadget for xi, any perfect matching must use either all gray triples (corresponding to xi = true) or all blue ones (corresponding to xi = false).
C・onstruction. (part 1)
・Create gadget for each variable xi with 2k core elements and 2k tip ones. ・No other triples will use core elements.
clause 1 tips
true
k = 2 clauses
n = 3 variables
false
core
clause 2 tips
x1
x2 x3
52
3-satisfiability reduces to 3-dimensional matching
C・onstruction. (part 2)
・Create gadget for each clause Cj with two elements and three triples. ・Exactly one of these triples will be used in any 3d-matching.
Ensures any perfect matching uses either (i) grey core of x1 or (ii) blue core of x2 or (iii) grey core of x3.
each clause assigned
its own 2 adjacent tips
C1
clause 1 gadget
false
clause 1 tips
true
core
x1
x2
x3
53
3-satisfiability reduces to 3-dimensional matching
C・onstruction. (part 3)
・There are 2 n k tips: n k covered by blue/gray triples; k by clause triples.
To cover remaining (n – 1) k tips, create (n – 1) k cleanup gadgets: same as clause gadget but with 2 n k triples, connected to every tip.
clause 1 gadget
C1
false
cleanup gadget
···
clause 1 tips
true
core
x1
x2
x3
54
3-satisfiability reduces to 3-dimensional matching
Lemma. Instance (X, Y, Z) has a perfect matching iff Φ is satisfiable. Q. What are X, Y, and Z ?
clause 1 gadget
C1
false
cleanup gadget
···
clause 1 tips
true
core
x1
x2
x3
55
3-satisfiability reduces to 3-dimensional matching
Lemma. Instance (X, Y, Z) has a perfect matching iff Φ is satisfiable.
Q. A.
What are X, Y, and Z ?
X = black, Y = white, and Z = blue.
clause 1 gadget
C1
false
cleanup gadget
···
clause 1 tips
true
core
x1
x2
x3
56
3-satisfiability reduces to 3-dimensional matching
Lemma. Instance (X, Y, Z) has a perfect matching iff Φ is satisfiable. Pf. ⇒ If 3d-matching, then assign xi according to gadget xi.
Pf. ⇐ If Φ is satisfiable, use any true literal in Cj to select gadget Cj triple. ▪ clause 1 gadget
C1
false
cleanup gadget
···
clause 1 tips
true
core
x1
x2
x3
57
SECTION 8.7
8. INTRACTABILITY I
‣ poly-time reductions
‣ packing and covering problems ‣ constraint satisfaction problems ‣ sequencing problems
‣ partitioning problems
‣ graph coloring
‣ numerical problems
3-colorability
3-COLOR. Given an undirected graph G, can the nodes be colored black, white, and blue so that no adjacent nodes have the same color?
yes instance
59
Intractability: quiz 6
How difficult to solve 2-COLOR?
A. O(m + n) using BFS or DFS.
B. O(mn) using maximum flow.
C. Ω(2n) using brute force.
D. Not even Tarjan knows.
60
Application: register allocation
Register allocation. Assign program variables to machine registers so that no more than k registers are used and no two program variables that are needed at the same time are assigned to the same register.
Interference graph. Nodes are program variables; edge between u and v
if there exists an operation where both u and v are “live” at the same time.
Observation. [Chaitin 1982] Can solve register allocation problem iff interference graph is k-colorable.
Fact. 3-COLOR ≤ P K-REGISTER-ALLOCATION for any constant k ≥ 3.
61
3-satisfiability reduces to 3-colorability
Theorem. 3-SAT ≤ P 3-COLOR.
Pf. Given 3-SAT instance Φ, we construct an instance of 3-COLOR that is 3-colorable iff Φ is satisfiable.
62
3-satisfiability reduces to 3-colorability
Construction.
(i) Create a graph G with a node for each literal.
(ii) Connect each literal to its negation.
(iii) Create 3 new nodes T, F, and B; connect them in a triangle.
(iv) Connect each literal to B.
(v) For each clause Cj, add a gadget of 6 nodes and 13 edges.
to be described later
TF
B
63
3-satisfiability reduces to 3-colorability
Lemma. Graph G is 3-colorable iff Φ is satisfiable. Pf. ⇒ Suppose graph G is 3-colorable.
・WLOG, assume that node T is colored black, F is white, and B is blue. ・Consider assignment that sets all black literals to true (and white to false). ・(iv) ensures each literal is colored either black or white.
・(ii) ensures that each literal is white if its negation is black (and vice versa).
true
T
base
false
F
B
64
3-satisfiability reduces to 3-colorability
Lemma. Graph G is 3-colorable iff Φ is satisfiable. Pf. ⇒ Suppose graph G is 3-colorable.
・WLOG, assume that node T is colored black, F is white, and B is blue. ・Consider assignment that sets all black literals to true (and white to false). ・(iv) ensures each literal is colored either black or white.
・(ii) ensures that each literal is white if its negation is black (and vice versa). ・(v) ensures at least one literal in each clause is black.
B
Cj =x1 ∨x2 ∨x3
6-node gadget
€
true
TF
false
65
3-satisfiability reduces to 3-colorability
Lemma. Graph G is 3-colorable iff Φ is satisfiable. Pf. ⇒ Suppose graph G is 3-colorable.
・WLOG, assume that node T is colored black, F is white, and B is blue. ・Consider assignment that sets all black literals to true (and white to false). ・(iv) ensures each literal is colored either black or white.
・(ii) ensures that each literal is white if its negation is black (and vice versa). ・(v) ensures at least one literal in each clause is black. ▪
suppose, for the sake of contradiction, that all 3 literals are white in some 3-coloring
Cj =x1 ∨x2 ∨x3 contradiction
€
B
(not a 3-coloring)
true
T💣F
false
66
3-satisfiability reduces to 3-colorability
Lemma. Graph G is 3-colorable iff Φ is satisfiable. Pf. ⇐ Suppose 3-SAT instance Φ is satisfiable.
・Color all true literals black and all false literals white. ・Pick one true literal; color node below that node white, ・and node below that blue.
・Color remaining middle row nodes blue.
Color remaining bottom nodes black or white, as forced. ▪
a literal set to true
B
in 3-SAT assignment
x3
€
Cj =x1 ∨x2 ∨x3
true
TF
false
67
Poly-time reductions
constraint satisfaction
3-SAT
INDEPENDENT-SET
VERTEX-COVER
SET-COVER
packing and covering
DIR-HAM-CYCLE
HAM-CYCLE
3-COLOR
SUBSET-SUM
KNAPSACK
sequencing
partitioning
numerical
68
3-SAT poly-time reduces to INDEPENDENT-SET
SECTION 8.8
8. INTRACTABILITY I
‣ poly-time reductions
‣ packing and covering problems ‣ constraint satisfaction problems ‣ sequencing problems
‣ partitioning problems
‣ graph coloring
‣ numerical problems
My hobby
NP-Complete by Randall Munro http://xkcd.com/287
Creative Commons Attribution-NonCommercial 2.5
70
Subset sum
SUBSET-SUM. Given n natural numbers w1, …, wn and an integer W, is there a subset that adds up to exactly W ?
Ex. { 215, 215, 275, 275, 355, 355, 420, 420, 580, 580, 655, 655 }, W = 1505. Yes. 215 + 355 + 355 + 580 = 1505.
Remark. With arithmetic problems, input integers are encoded in binary. Poly-time reduction must be polynomial in binary encoding.
71
Subset sum
Theorem. 3-SAT ≤ P SUBSET-SUM.
Pf. Given an instance Φ of 3-SAT, we construct an instance of SUBSET-SUM that has solution iff Φ is satisfiable.
72
3-satisfiability reduces to subset sum
Construction. Given 3-SAT instance Φ with n variables and k clauses, fo・rm 2n + 2k decimal integers, each having n + k digits:
・Include one digit for each variable xi and one digit for each clause Cj. ・Include two numbers for each variable xi.
・Include two numbers for each clause Cj. Sum of each xi digit is 1;
sum of each Cj digit is 4.
Key property. No carries possible ⇒
x1 ¬ x1 x2 ¬ x2 x3 ¬ x3
100,010
100,101
10,100
10,011
1,110
1,001
100
200
10
20
1
2
111,444
x1
1
1
0
0
0
0
0
0
0
0
0
0
1
x2
0
0
1
1
0
0
0
0
0
0
0
0
1
x3
0
0
0
0
1
1
0
0
0
0
0
0
1
C1
1
0
1
0
1
2
0
0
0
0
4
C2
0
1
1
0
0
0
1
2
0
0
4
C3
010 101
0
1
0
1
0
0
0
0
1
2
4
each digit yields one equation.
C1 = C2 = C3 =
¬ x1 x1 ¬ x1
∨ x2 ∨ x3 ∨¬x2∨ x3 ∨ ¬x2 ∨ ¬x3
dummies to get clause columns to sum to 4
3-SAT instance
W
SUBSET-SUM instance
73
3-satisfiability reduces to subset sum
Lemma. Φ is satisfiable iff there exists a subset that sums to W. P・f. ⇒ Suppose 3-SAT instance Φ has satisfying assignment x*.
If x* = true, select integer in row xi ; i
・otherwise, select integer in row ¬ xi. ・Each xi digit sums to 1.
Since Φ is satisfiable, each Cj digit sums ・to at least 1 from xi and ¬ xi rows.
Select dummy integers to make Cj digits sum to 4. ▪
x1
¬ x1 x2
¬ x2 x3
¬ x3
100,010
100,101
10,100
10,011
1,110
1,001
100
200
10
20
1
2
111,444
x1
1
1
0
0
0
0
0
0
0
0
0
0
1
x2
0
0
1
1
0
0
0
0
0
0
0
0
1
x3
0
0
0
0
1
1
0
0
0
0
0
0
1
C1
0
1
1
0
1
0
1
2
0
0
0
0
4
C2
1
0
0
1
1
0
0
0
1
2
0
0
4
C3
0
1
0
1
0
1
0
0
0
0
1
2
4
C1=¬x1∨ x2∨ x3 C2= x1∨¬x2∨ x3 C3 = ¬x1 ∨ ¬x2 ∨ ¬x3
dummies to get clause columns to sum to 4
3-SAT instance
W
SUBSET-SUM instance
74
3-satisfiability reduces to subset sum
Lemma. Φ is satisfiable iff there exists a subset that sums to W. P・f. ⇐ Suppose there exists a subset S* that sums to W.
・Digit xi forces subset S* to select either row xi or row ¬ xi (but not both). If row xi selected, assign x* = true ; otherwise, assign x* = false.
ii Digit Cj forces subset S* to select
x1
1
1
0
0
0
0
0
0
0
0
0
0
1
x2
0
0
1
1
0
0
0
0
0
0
0
0
1
x3
0
0
0
0
1
1
0
0
0
0
0
0
1
C1
0
1
1
0
1
0
1
2
0
0
0
0
4
C2
1
0
0
1
1
0
0
0
1
2
0
0
4
C3
0
1
0
1
0
1
0
0
0
0
1
2
4
at least one literal in clause. ▪
x1
¬ x1 x2
¬ x2 x3
¬ x3
100,010
100,101
10,100
10,011
1,110
1,001
100
200
10
20
1
2
111,444
C1=¬x1∨ x2∨ x3 C2= x1∨¬x2∨ x3 C3 = ¬x1 ∨ ¬x2 ∨ ¬x3
dummies to get clause columns to sum to 4
3-SAT instance
W
SUBSET-SUM instance
75
SUBSET SUM REDUCES TO KNAPSACK
SUBSET-SUM. Given n natural numbers w1, …, wn and an integer W, is there a subset that adds up to exactly W ?
KNAPSACK. Given a set of items X, weights ui ≥ 0, values vi ≥ 0, a weight limit U, and a target value V, is there a subset S ⊆ X such that:
ui U, vi V i S i S
Recall. O(n U) dynamic programming algorithm for KNAPSACK. Challenge. Prove SUBSET-SUM ≤ P KNAPSACK.
Pf. Given instance (w1, …, wn, W) of SUBSET-SUM, create KNAPSACK instance:
ui =vi =wi U=V=W
wi W, wi W i S i S
76
2 kg
6 kg
1 kg
5 kg
7 kg
11 kg
$18
$6
$1
$28
$22
Poly-time reductions
constraint satisfaction
3-SAT
INDEPENDENT-SET
VERTEX-COVER
SET-COVER
packing and covering
DIR-HAM-CYCLE
HAM-CYCLE
3-COLOR
SUBSET-SUM
KNAPSACK
sequencing
partitioning
numerical
77
3-SAT poly-time reduces to INDEPENDENT-SET
Karp’s 20 poly-time reductions from satisfiability
Dick Karp (1972)
1985 Turing Award
78