ppt - CSE Labs User Home Pages

Download Report

Transcript ppt - CSE Labs User Home Pages

CSci 4011
INHERENT LIMITATIONS
OF COMPUTER PROGRAMS
HARDEST PROBLEMS IN NP
Theorem: A language B is NP-complete if:
Definition:
1. B  NP
2. A
Every
A in NP is poly-time
reducible to B
is NP-complete
and A ·P B
(i.e. B is NP-hard)
If B is NP-Complete and P  NP, then
There is no fast algorithm for B.
We will use 3SAT to prove other problems are
NP-Complete or NP-Hard. Examples include
3SAT ≤P NAESAT, 2CSP…
3SAT ≤P CLIQUE
3SAT ≤P 0/1-ILP
3SAT ≤P HAMPATH
3SAT ≤P 3COLOR
3SAT ≤P GRADUATION
3SAT ≤P VERTEX-COVER
REDUCTION STRATEGIES
A reduction by restriction shows that the source
problem is a special case of the target problem.
For example, 3SAT ≤P CNF-SAT because every
satisfiable 3CNF is also a satisfiable CNF.
Example. Prove 3SAT ≤P 4SAT by restriction.
A 3CNF can be converted to an equivalent 4CNF
by repeating one literal in each clause.
VERTEX COVER
a
a
d
c
b
d
c
e
b
e
VERTEX-COVER = {〈G,k〉 | G has a vertex cover
of size at most k }
INDEPENDENT SET
a
a
d
c
b
d
c
e
b
e
INDSET = { 〈G,k〉 | G has an independent set
of size at least k }
Prove that VERTEX-COVER ≤P INDSET.
SUBSET SUM
SUBSET-SUM = { 〈y1,…, yn,t〉 |∃S⊆{1,…,n}. Σj∈S yj=t }
Which of the following are in SUBSET-SUM?
YES
〈1,3,5,7, 10〉
NO
〈19,11,27,4, 13〉
YES
〈19,11,27,4, 61〉
KNAPSACK = {〈(w1,v1)…,(wn,vn),W, V〉| ∃S⊆{1…n}
so that Σi∈Swi ≤ W and Σi∈Svi ≥ V}
15 lbs
$500
½ lb
$15
3 lbs
$2000
1lb,
50 × $20
Theorem. SUBSET-SUM ≤P KNAPSACK
Proof.
A subset sum instance is a knapsack where the
weights are equal to the values:
Let ƒ(y1,…,yn,t) = 〈(y1,y1)…(yn,yn),t,t〉.
Then ∃S. Σi∈S yi = t iff
∃S. Σi∈S yi ≥ t and Σi∈S yi ≤ t, so
〈y1…yn,t〉 ∈ SUBSET-SUM iff ƒ(y1…yn,t)∈ KNAPSACK
SET-COVER = {〈S1,…,Sn,k〉 | ∀i,Si⊆U and∃i[1…k]
so that Si[1]∪Si[2]∪…∪Si[k] = U }
Which of the following are in SET-COVER?
YES
〈{1}, {1,2}, {2}, {3}, 2〉
NO
〈{1,4}, {1,2}, {1,3}, {4}, 2〉
YES
〈{1}, {2}, {1,2}, 2〉
Theorem. VERTEX-COVER ≤P SET-COVER
Proof. A vertex cover instance is just a set cover
instance where every node is a set of edges.
REDUCTION STRATEGIES
A reduction from A to B by local replacement
shows how to “translate” between “units” of A
and “units” of B.
Example. vertex cover “units” are vertices and
edges; set cover “units” are elements and sets.
Example. CIRCUIT-SAT units are gates, CNFSAT
units are clauses, 3SAT units are 3-literal clauses.
GRADUATION
A transcript is a set of course numbers a student
has taken
A major consists of:
Pairs: exactly one of which must be taken
Lists: at least one course of which must be taken
GRADUATION = {〈T,M〉 | a subset of T satisfies M}
For example:
T = {1901A, 1902B, 1902A, 2011, 4041A, 4061, 4211}
M = [1901A,1901B], [1902A,1902B]
(4011,4041A,4041B), (4211,4707), (4061)
GRADUATION ∈ NP:
The subset is a proof that (T,M) ∈ GRADUATION.
3SAT ≤P GRADUATION:
(x1 ⋁ x2 ⋁ ¬x3) ∧
(¬x1 ⋁ x2 ⋁ x2) ∧
(¬x2 ⋁ x3 ⋁ x1)
T = {101, 102,
201, 202,
301, 302}
M = [101, 102],
[201, 202],
[301, 302]
(101,201,302),
(101,201,201),
(101,202,301)
GRADUATION ∈ NP:
The subset is a proof that (T,M) ∈ GRADUATION.
3SAT ≤P GRADUATION:
Let  = C1 ∧ C2∧ … ∧Cm have variables x1…xk
For each xi:
add classes i01 and i02 to T.
add pair (i01,i02) to M.
For each Cj, we add a triple to M:
if xi is a literal in Cj, the triple includes i01.
if ¬xi is a literal in Cj, the triple includes i02.
3SAT P SUBSET-SUM
We transform a 3-cnf formula  into 〈y1…yn, t〉:
  3SAT  〈y1…yn,t〉  SUBSET-SUM
The transformation can be done in time
polynomial in the length of 
Each variable and each clause result in two yi’s. Each
yi will have a digit for each clause and variable.
x2 x1 C3 C2 C1
x1
(x1 ⋁ x2 ⋁ x2) ∧
(¬x1 ⋁ x2⋁ x2) ∧
(x1 ⋁ ¬x2 ⋁ x2)
x2
C3
C2
C1
y1
y2
y3
1
1
1 0
1
0
1
0
1
1
1
0
1
y4
y5
y6
1 0
1
1
1
0
0
0
0
0
0
1
1
0
0
1
y7
y8
y9
y10
t
1 1
3
3
1
3
3SAT P SUBSET-SUM
Let  = C1 ∧ C2 ∧ … Cm have k variables x1…xk.
We output y1 … y2k + 2m, each a k+m-digit number.
for each 1 ≤ j ≤ k:
for each 1 ≤ I ≤ m:
the ith digit of y2j-1 is 1 if xj ∈ Ci, else 0
the ith digit of y2j is 1 if ¬xj ∈ Ci, else 0.
digit j+m of y2j, y2j-1 is 1.
For each 1 ≤ j ≤ m: y2k+2j = y2k+2j-1 = 10j-1
Output t = 11..1133..3
REDUCTION STRATEGIES
A reduction by component design constructs
gadgets that simulate variables and clauses.
In particular a reduction must provide:
a gadget to force the solution to the target
instance to choose either x or ¬x
a gadget to force the solution to the target
instance to choose one literal from each clause
a gadget to force the solution to the target
instance to satisfy every clause
K-CLIQUES
a
d
f
e
g
c
b
3SAT P CLIQUE
We transform a 3-cnf formula  into 〈G,k〉 such that
  3SAT  〈G,k〉  CLIQUE
The transformation can be done in time
polynomial in the length of 
(x1  x1  x2)  (x1  x2  x2)  (x1  x2  x2)
x1
x2
x2
x1
x1
x1
x2
x2
x2
k = #clauses
(x1  x1  x1)  (x1  x1  x2) 
(x2  x2  x2)  (x2  x2  x1)
x1
x1
x2
x1
x2
x1
x2
x1
x2
x2
x2
x1
3SAT P CLIQUE
We transform a 3-cnf formula  into 〈G,k〉 such that
  3SAT  〈G,k〉  CLIQUE
If  has k clauses, we create a graph with k
clusters of 3 nodes each. Each cluster
corresponds to a clause. Each node in a
cluster is labeled with a literal from the clause.
We do not connect any nodes in the same cluster
We connect nodes in different clusters whenever
they are not contradictory
3SAT P CLIQUE
We transform a 3-cnf formula  into 〈G,k〉 such that
  3SAT  〈G,k〉  CLIQUE
 is satisfiable iff there is an assignment that
makes at least one literal true in each clause.
The nodes corresponding to these k true literals
do not contradict each other, so they form a kclique in G.
A k-clique in G must have one node from each
cluster. Setting the corresponding literals to true
will satisfy 
3-COLORING
a
d
a
d
e
b
c
c
b
3SAT P 3COLOR
We transform a 3-cnf formula  into a graph G so
  3SAT  G  3COLOR
The transformation can be done in time
polynomial in the length of 
(x1 ⋁ x2 ⋁ x2)
?
F
T
x1
x1
x2
x2
(x1 ⋁ x2 ⋁ x2)
?
T
F
c11
c12
c13
c14
c15
c16
x1
x1
x2
x2
(x1 ⋁ x2 ⋁ x2) ∧ (x2 ⋁ ¬x1 ⋁ ¬x1)
?
T
F
x1
x1
x2
x2
c11
c12
c13
c11
c12
c13
c14
c15
c16
c14
c15
c16
(x1 ⋁ x2 ⋁ x2) ∧ (x2 ⋁ ¬x1 ⋁ ¬x1)
?
T
F
x1
x1
x2
x2
c11
c12
c13
c11
c12
c13
c14
c15
c16
c14
c15
c16