Document

Theoretical Computer Science I
Practice lecture
Jian Liu
Institute for Theoretical Computer Science
Graz University of Technology
2017.05.19
Today
3-SAT is NP-complete
CLIQUE is NP-Complete
HAMILTON-Cycle is NP-complete (practice)
HAMILTON-PATH is NP-Complete (practice)
Theorem:
If problem A ≤P problem B and problem B is in P, then
problem A is also in P.
algorithm for
problem A
input to

problem A

reduction
algorithm
input to
problem B algorithm for

problem B
polynomial-time
output to
problem B
=
output to
problem A
A first NP-complete problem: Circuit-SAT
x1
x2
AND
AND
NOT
OR
x3
OR
NOT
x4
AND
AND
Circuit-SAT
Input: Boolean combinatorial circuit
Question: Can variables be set such that circuit evaluates to true ?
computed value
A first NP-complete problem: Circuit-SAT
x1
x2
AND
AND
NOT
OR
x3
x4
AND
computed value
OR
NOT
AND
Lemma 1: Circuit-SAT is in NP
Proof. Must show that there exists a polynomial-time verifier.
Consider “yes”-instance x (so: x = description of satisfiable circuit)
certificate y: take satisfying truth assignment
We can easily check in polynomial time if truth assignment produces TRUE.
A first NP-complete problem: Circuit-SAT
x1
x2
AND
AND
NOT
OR
x3
x4
AND
computed value
OR
NOT
AND
Lemma 2: For every problem A in NP, we have:
A ≤P Circuit-SAT
Lemma: For every problem A in NP, we have:
A ≤P Circuit-SAT
Proof: (sketch of sketch of …)
Step 1: show the following:
if an algorithm runs in polynomial time, then there is a polynomial-size
Boolean circuit that “implements” the algorithm, and such a circuit can
be constructed in polynomial time
(idea: algorithm runs on computer that is essentially a Boolean circuit)
Lemma: For every problem A in NP, we have:
A ≤P Circuit-SAT
Proof: (sketch of sketch of …)
Step 2: Describe algorithm that performs reduction:
 A in NP, so A has verification algorithm VER(x,y) that checks if x is
“yes”-instance using certificate y. Construct circuit implementing VER.
x1
circuit implementing VER
xn
y1
ym
 “Fix” the variables corresponding to x according to the given input
 Run Circuit-SAT
Circuit-SAT returns “yes”
iff x is “yes” instance for problem A
A first NP-complete problem: Circuit-SAT
x1
x2
AND
AND
NOT
OR
x3
x4
AND
computed value
OR
NOT
AND
Lemma 1: Circuit-SAT is in NP
Lemma 2: For every problem A in NP, we have:
A ≤P Circuit-SAT
(in other words: Circuit-SAT is NP-hard).
Theorem: Circuit-Sat is NP-complete.
Circuit-Sat is NP-complete
Proof by hand-waving. CIRCUIT-SAT is clearly in NP.
The "certificate” is a satisfying assignment. Given this,
we can easily verify in polynomial time that the circuit
outputs a 1.
We now give a polynomial-time transformation from
every problem L in NP to CIRCUIT-SAT. If L is in NP,
then there is a verifier A(x,y) that runs in time T(|x|) =
O(|x|k) for some k. We now construct a single boolean
circuit M that maps one "configuration" of a machine
that carries out the computation of A(x,y) (recording
such things as the memory state, program counter,
etc.) to the next "configuration".
Circuit-Sat is NP-complete
We now hook together T(|x|) of these circuits together,
making the inputs to the circuit at the top the value of y,
and the output the single bit that reflects the value of
A(x,y). This big circuit C(x) is satisfiable (by a value of
y) if and only if x was a "yes" instance of L.
The size of this circuit is polynomial in x, and the
transformation can be done in polynomial time
Proving NP-completeness of other problems
Theorem: If problem A is NP-hard and problem A ≤P problem B,
then problem B is also NP-hard.
General strategy to prove that a problem B is NP-complete
1. Select problem A that is known to be NP-complete.
2. Prove that A ≤P B:
i.
Describe reduction algorithm, which maps instances x of A to instances
f (x) of B.
ii.
Prove that x is “yes”-instance for A
iff
f (x) is “yes”-instance for B
iii. Prove that reduction algorithm runs in polynomial time
(Now you have shown that B is NP-hard.)
3. Prove that B is in NP by giving polynomial-time verification algorithm.
Travelling salesman problem (TSP)
Input: complete, weighted undirected graph G, and a number k
Question: does G have a tour of length at most k visiting all nodes?
33
17
Claim: TSP is in NP
Proof:
Consider “yes”-instance x = (G,k).
Let y be a tour in G of length at most k.
Verifier: must check in polynomial time that
 y is a tour visiting all nodes
 length(y) ≤ k.
Notes:
− verifying optimization problem is much harder
− verifying “no”-instance is much harder
8
15
Reductions
problem A is polynomial-time reducible to problem B if there is a reduction
algorithm mapping instances of A to instances of problem B such that
“yes”-instances of A are mapped to “yes”-instances of B
“no”-instances of A are mapped to “no”-instances of B
the reduction algorithm runs in polynomial time
Notation: problem A ≤P problem B
Example: Hamiltonion Cycle ≤P TSP
HamiltonianCycle
Input: undirected graph G=(V,E)
Question: is there a tour in G? (tour = cycle visiting every node exactly once)
TSP
Input: complete, weighted undirected graph G=(V,E), and a number k
Question: is there a tour of length at most k?
Theorem: Hamiltonian Cycle ≤P TSP
G:
G*: old edges weight 0
reduction
algorithm
Proof.
G has Hamiltonian cycle iff G* has tour of length at most 0
new edges: weight 1
HAMILTON-Cycle is NP-complete
Proof.
Step 1: Select suitable NP-hard problem:
Circuit-Sat, SATISFIABILITY, 3-SAT, CLIQUE,
VertexCover, SubsetSum?
Vertex Cover
Step 2: Give polynomial-time reduction from Vertex Cover to
Ham-Cycle
A polynomial-time reduction from Vertex Cover to Ham-Cycle
HAMILTON-Cycle is NP-complete
Proof.
Step 1: Select suitable NP-hard problem:
Circuit-Sat, SATISFIABILITY, 3-SAT, CLIQUE,
VertexCover, SubsetSum?
Vertex Cover
Step 2: Give polynomial-time reduction from Vertex Cover to
Ham-Cycle
Complicated, but can be done.
Step 3. Prove Ham-Cycle in NP by giving polynomial-time
verification algorithm.
certificate = permutation of vertices forming a cycle
HAMILTON-Cycle is NP-complete
Proof.
Step 1: Select suitable NP-hard problem:
Circuit-Sat, SATISFIABILITY, 3-SAT, CLIQUE,
VertexCover, SubsetSum?
3-SAT
Step 2: Give polynomial-time reduction from 3-SAT to HamCycle
NEW (next)
Step 3. Prove Ham-Cycle in NP by giving polynomial-time
verification algorithm.
certificate = permutation of vertices forming a cycle
HAMILTON-Cycle is NP-complete
HAMILTON-Cycle is NP-complete
Reduction Idea (very high level):
• Create some graph structure (a “gadget") that
represents the variables
• And some graph structure that represents the
clauses
• Hook them up in some way that encodes the
formula
• Show that this graph has a Ham. cycle i the formula
is satisfiable.
Hooking in the Clauses
Add a new node for each clause:
HAMILTON-Cycle is NP-complete
Gadget Representing the Variables
HAMILTON-Cycle is NP-complete
Connecting up the paths
HAMILTON-Cycle is NP-complete
•
A Hamiltonian path encodes a truth assignment
for the variables (depending on which direction
each chain is traversed)
•
For there to be a Hamiltonian cycle, we have to
visit every clause node
•
We can only visit a clause if we satisfy it (by
setting one of its terms to true)
•
Hence, if there is a Hamiltonian cycle, there is a
satisfying assignment
HAMILTON-PATH is NP-complete
Hamiltonian Path: Does G contain a path that visits every
node exactly once?
How could you prove this problem is NP-complete?
Reduce Hamiltonian Cycle to Hamiltonian Path.
Given instance of Hamiltonian Cycle G, choose an arbitrary
node v and split it into two nodes to get graph G’:
Now any Hamiltonian Path must start at v’ and end at v’’.
HAMILTON-PATH is NP-complete
G’’ has a Hamiltonian Path <=> G has a Hamiltonian Cycle.
=> If G’’ has a Hamiltonian Path, then the same
ordering of nodes (after we glue v’ and v’’ back
together) is a Hamiltonian cycle in G.
<= If G has a Hamiltonian Cycle, then the same
ordering of nodes is a Hamiltonian path of G’ if we
split up v into v’ and v’’.
Hence, Hamiltonian Path is NP-complete.
HAMILTON-PATH is NP-complete
Proof.
Step 1: Select suitable NP-hard problem:
Circuit-Sat, SATISFIABILITY, 3-SAT, CLIQUE,
VertexCover, SubsetSum?
3-SAT
Step 2: Give polynomial-time reduction from 3-SAT to HamCycle
See the Skriptum