lecture23
lecture23
Chandra Chekuri
[email protected]
3228 Siebel Center
University of Illinois, Urbana-Champaign
Fall 2010
Chekuri CS473 1
Recap
Chekuri CS473 2
Recap
Chekuri CS473 2
Recap
Chekuri CS473 2
Recap
Theorem (Cook-Levin)
Circuit-SAT and SAT are NP-Complete.
Chekuri CS473 2
Recap contd
Theorem (Cook-Levin)
Circuit-SAT and SAT are NP-Complete.
Chekuri CS473 3
Today
Prove
Hamiltonian Cycle Problem is NP-Complete
3-Coloring is NP-Complete
Chekuri CS473 4
Directed Hamiltonian Cycle
Chekuri CS473 5
Directed Hamiltonian Cycle
Chekuri CS473 5
Directed Hamiltonian Cycle
Chekuri CS473 5
Directed Hamiltonian Cycle is NP-complete
Chekuri CS473 6
Directed Hamiltonian Cycle is NP-complete
Chekuri CS473 6
Directed Hamiltonian Cycle is NP-complete
Chekuri CS473 6
Directed Hamiltonian Cycle is NP-complete
Chekuri CS473 6
Reduction
Chekuri CS473 7
Reduction: First Ideas
Chekuri CS473 8
Reduction: First Ideas
Chekuri CS473 8
Reduction: First Ideas
Chekuri CS473 8
The Reduction: Phase I
x1
x2
x3
Chekuri CS473 9
The Reduction: Phase II
x1
x2
x3
Chekuri CS473 10
Correctness Proof
Proposition
ϕ has a satisfying assignment iff Gϕ has a Hamiltonian cycle
Chekuri CS473 11
Correctness Proof
Proposition
ϕ has a satisfying assignment iff Gϕ has a Hamiltonian cycle
Proof.
Chekuri CS473 11
Correctness Proof
Proposition
ϕ has a satisfying assignment iff Gϕ has a Hamiltonian cycle
Proof.
⇒ Let a be the satisfying assignment for ϕ. Define Hamiltonian
cycle as follows
Chekuri CS473 11
Correctness Proof
Proposition
ϕ has a satisfying assignment iff Gϕ has a Hamiltonian cycle
Proof.
⇒ Let a be the satisfying assignment for ϕ. Define Hamiltonian
cycle as follows
If a(xi ) = 1 then traverse path i from left to right
Chekuri CS473 11
Correctness Proof
Proposition
ϕ has a satisfying assignment iff Gϕ has a Hamiltonian cycle
Proof.
⇒ Let a be the satisfying assignment for ϕ. Define Hamiltonian
cycle as follows
If a(xi ) = 1 then traverse path i from left to right
If a(xi ) = 0 then traverse path i from right to left
Chekuri CS473 11
Correctness Proof
Proposition
ϕ has a satisfying assignment iff Gϕ has a Hamiltonian cycle
Proof.
⇒ Let a be the satisfying assignment for ϕ. Define Hamiltonian
cycle as follows
If a(xi ) = 1 then traverse path i from left to right
If a(xi ) = 0 then traverse path i from right to left
For each clause, path of at least one variable is in the “right”
direction to splice in the node corresponding to clause
Chekuri CS473 11
Hamiltonian Cycle ⇒ Satisfying assignment
Chekuri CS473 12
Hamiltonian Cycle ⇒ Satisfying assignment
Chekuri CS473 12
Hamiltonian Cycle ⇒ Satisfying assignment
Chekuri CS473 12
Hamiltonian Cycle ⇒ Satisfying assignment
Chekuri CS473 12
Example
x1
x2
x3
Chekuri CS473 13
Hamiltonian Cycle ⇒ Satisfying assignment (contd)
Chekuri CS473 14
Hamiltonian Cycle ⇒ Satisfying assignment (contd)
Chekuri CS473 14
Hamiltonian Cycle ⇒ Satisfying assignment (contd)
Chekuri CS473 14
Hamiltonian Cycle
Problem
Input Given undirected graph G = (V , E )
Goal Does G have a Hamiltonian cycle? That is, is there a
cycle that visits every vertex exactly one (except start
and end vertex)?
Chekuri CS473 15
NP-completeness
Theorem
Hamiltonian cycle problem for undirected graphs is NP-complete
Chekuri CS473 16
NP-completeness
Theorem
Hamiltonian cycle problem for undirected graphs is NP-complete
Proof.
Chekuri CS473 16
NP-completeness
Theorem
Hamiltonian cycle problem for undirected graphs is NP-complete
Proof.
The problem is in NP; proof left as exercise
Chekuri CS473 16
NP-completeness
Theorem
Hamiltonian cycle problem for undirected graphs is NP-complete
Proof.
The problem is in NP; proof left as exercise
Hardness proved by reducing Directed Hamiltonian Cycle to
this problem
Chekuri CS473 16
Reduction Sketch
a c
v
b d
Chekuri CS473 17
Reduction Sketch
a c
v
b d
Chekuri CS473 17
Reduction Sketch
a c
v
b d
Chekuri CS473 17
Reduction Sketch
a c ao ci
v vi v vo
b d bo di
Chekuri CS473 17
Reduction: Wrapup
Chekuri CS473 18
Graph Coloring
Chekuri CS473 19
Graph 3-Coloring
Chekuri CS473 20
Graph 3-Coloring
Chekuri CS473 20
Graph Coloring
Chekuri CS473 21
Graph Coloring
Chekuri CS473 21
Graph Coloring
Chekuri CS473 21
Graph Coloring
Chekuri CS473 21
Graph Coloring and Register Allocation
Register Allocation
Assign variables to (at most) k registers such that variables needed
at the same time are not assigned to the same register
Chekuri CS473 22
Graph Coloring and Register Allocation
Register Allocation
Assign variables to (at most) k registers such that variables needed
at the same time are not assigned to the same register
Interference Graph
Vertices are variables, and there is an edge between two vertices, if
the two variables are “live” at the same time.
Chekuri CS473 22
Graph Coloring and Register Allocation
Register Allocation
Assign variables to (at most) k registers such that variables needed
at the same time are not assigned to the same register
Interference Graph
Vertices are variables, and there is an edge between two vertices, if
the two variables are “live” at the same time.
Observations
Chekuri CS473 22
Graph Coloring and Register Allocation
Register Allocation
Assign variables to (at most) k registers such that variables needed
at the same time are not assigned to the same register
Interference Graph
Vertices are variables, and there is an edge between two vertices, if
the two variables are “live” at the same time.
Observations
[Chaitin] Register allocation problem is equivalent to coloring
the interference graph with k colors
Chekuri CS473 22
Graph Coloring and Register Allocation
Register Allocation
Assign variables to (at most) k registers such that variables needed
at the same time are not assigned to the same register
Interference Graph
Vertices are variables, and there is an edge between two vertices, if
the two variables are “live” at the same time.
Observations
[Chaitin] Register allocation problem is equivalent to coloring
the interference graph with k colors
Moreover, 3-COLOR ≤P k − Register Allocation, for any
k ≥3
Chekuri CS473 22
Class Room Scheduling
Chekuri CS473 23
Class Room Scheduling
Create graph G
a node vi for each class i
an edge between vi and vj if classes i and j conflict
Chekuri CS473 23
Class Room Scheduling
Create graph G
a node vi for each class i
an edge between vi and vj if classes i and j conflict
Chekuri CS473 23
Frequency Assignments in Cellular Networks
Chekuri CS473 24
Frequency Assignments in Cellular Networks
Chekuri CS473 24
3-Coloring is NP-Complete
3-Coloring is in NP
Certificate: for each node a color from {1, 2, 3}
Certifier: Check if for each edge (u, v ), the color of u is
different from that of v
Hardness: We will show 3-SAT ≤P 3-Coloring
Chekuri CS473 25
Reduction Idea
Chekuri CS473 26
Reduction Idea
Chekuri CS473 26
Reduction Idea
Chekuri CS473 26
Reduction Idea
Chekuri CS473 26
Reduction Idea
Chekuri CS473 26
Figure
T F
v¯n
Base
v1
vn
v¯1
v¯2
v2
Chekuri CS473 27
Clause Satisfiability Gadget
Chekuri CS473 28
Clause Satisfiability Gadget
OR-gadget-graph:
a
a∨b
a∨b∨c
b
Chekuri CS473 28
OR-Gadget Graph
Chekuri CS473 29
Reduction
a
a∨b
T
a∨b∨c
b
Base
c F
Chekuri CS473 30
Reduction
a
a∨b
T
a∨b∨c
b
Base
c F
Claim
No legal 3-coloring of above graph (with coloring of nodes T , F , B
fixed) in which a, b, c are colored False. If any of a, b, c are colored
True then there is a legal 3-coloring of above graph.
Chekuri CS473 31
Reduction Outline
Example
ϕ = (u ∨ ¬v ∨ w ) ∧ (v ∨ x ∨ ¬y )
OR−gates
~u u
~v v
~w w
~x x
~y y
Chekuri CS473 32
Correctness of Reduction
Chekuri CS473 33
Correctness of Reduction
Chekuri CS473 33
Correctness of Reduction
Chekuri CS473 33
Correctness of Reduction
Chekuri CS473 33
Correctness of Reduction
Chekuri CS473 33
Other NP-Complete Problems
3-Dimensional Matching
Subset Sum
Read book.
Chekuri CS473 34
Need to Know NP-Complete Problems
3-SAT
Circuit-SAT
Independent Set
Vertex Cover
Clique
Set Cover
Hamiltonian Cycle in Directed/Undirected Graphs
3-Coloring
3-D Matching
Subset Sum
Chekuri CS473 35
Subset Sum and Knapsack
Chekuri CS473 36
Subset Sum and Knapsack
Chekuri CS473 36
Subset Sum and Knapsack
Chekuri CS473 36
Subset Sum and Knapsack
Chekuri CS473 36
Subset Sum and Knapsack
Chekuri CS473 37
Subset Sum and Knapsack
Chekuri CS473 37
Subset Sum and Knapsack
Chekuri CS473 37