np-completenes, special caseslazsa/combopt2020spring/seventh_lecture_co_20… · 3-sat ˚clique for...

29
NP-Completenes, Special cases László Papp BME 30th of March, 2020

Upload: others

Post on 04-Jul-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

NP-Completenes, Special cases

László Papp

BME

30th of March, 2020

Page 2: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

3-SAT ≺ CLIQUEFor the input φ = (l11 ∨ l12 ∨ l13 ) ∧ (l21 ∨ l22 ∨ l23 ) ∧ . . . ∧ (lk1 ∨ lk2 ∨ lk3 )the reduction creates the following graph:The vertices of the graph are l ij (the j th literal of the i th clause).l ij and lmn are adjacent if and only if i 6= m and l ij 6= ¬lmn .(The corresponding literals are not in the same close and theyare not the negate of each other.)We search for a clique of size ≥ k (the number of clauses).

¬x1 ¬x2 x3

x2 ¬x3x1

x1

¬x2

x3

F(x1 ∨ x2 ∨ ¬x3)∧∧(¬x1 ∨ ¬x2 ∨ x3)∧∧(x1 ∨ ¬x2 ∨ x3)∧

F can be calculated in O(|φ|2) time, so in polynomial time.

Page 3: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

Correctness of the reductionConsider an assignment which satisfies φ. In each clause thereis a literal which is true. These literals span a clique of size k .

¬x1 ¬x2 x3

x2 ¬x3x1

x1

¬x2

x3

F(x1 ∨ x2 ∨ ¬x3)∧∧(¬x1 ∨ ¬x2 ∨ x3)∧∧(x1 ∨ ¬x2 ∨ x3)∧

A clique does not contain two literals from the same clause.Therefore if the size of a clique is the number of the clauses,then this clique contains one literal from each clause. Settingthese literals to true satisfy φ. We can set all of these literalstrue because none of them is a negate of an other onecontained in the clique.

Page 4: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

Correctness of the reductionConsider an assignment which satisfies φ. In each clause thereis a literal which is true. These literals span a clique of size k .

¬x1 ¬x2 x3

x2 ¬x3x1

x1

¬x2

x3

F(x1 ∨ x2 ∨ ¬x3)∧∧(¬x1 ∨ ¬x2 ∨ x3)∧∧(x1 ∨ ¬x2 ∨ x3)∧

A clique does not contain two literals from the same clause.Therefore if the size of a clique is the number of the clauses,then this clique contains one literal from each clause. Settingthese literals to true satisfy φ. We can set all of these literalstrue because none of them is a negate of an other onecontained in the clique.

Page 5: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

Summary of this lecture

A decision problem π is NP-Hard if for each α ∈ NP α ≺ π.A decision problem π is NP-Complete if for each α ∈ NP α ≺ πand π ∈ NP.

3SAT ∈ NP-Complete3SAT ≺ CLIQUECLIQUE ∈ NP

=⇒

CLIQUE ∈ NP-Complete

CLIQUE ∈ NP-CompleteCLIQUE ≺ VERTEX COVERVERTEX COVER ∈ NP

=⇒ VERTEX COVER∈ NP-Complete

Page 6: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

Summary of this lecture

A decision problem π is NP-Hard if for each α ∈ NP α ≺ π.A decision problem π is NP-Complete if for each α ∈ NP α ≺ πand π ∈ NP.

3SAT ∈ NP-Complete3SAT ≺ CLIQUECLIQUE ∈ NP

=⇒ CLIQUE ∈ NP-Complete

CLIQUE ∈ NP-CompleteCLIQUE ≺ VERTEX COVERVERTEX COVER ∈ NP

=⇒ VERTEX COVER∈ NP-Complete

Page 7: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

Summary of this lecture

A decision problem π is NP-Hard if for each α ∈ NP α ≺ π.A decision problem π is NP-Complete if for each α ∈ NP α ≺ πand π ∈ NP.

3SAT ∈ NP-Complete3SAT ≺ CLIQUECLIQUE ∈ NP

=⇒ CLIQUE ∈ NP-Complete

CLIQUE ∈ NP-CompleteCLIQUE ≺ VERTEX COVERVERTEX COVER ∈ NP

=⇒

VERTEX COVER∈ NP-Complete

Page 8: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

Summary of this lecture

A decision problem π is NP-Hard if for each α ∈ NP α ≺ π.A decision problem π is NP-Complete if for each α ∈ NP α ≺ πand π ∈ NP.

3SAT ∈ NP-Complete3SAT ≺ CLIQUECLIQUE ∈ NP

=⇒ CLIQUE ∈ NP-Complete

CLIQUE ∈ NP-CompleteCLIQUE ≺ VERTEX COVERVERTEX COVER ∈ NP

=⇒ VERTEX COVER∈ NP-Complete

Page 9: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

VERTEX COVER ≺ HAMILTONIAN

A Karp-reduction from VERTEX COVER to HAMILTONIAN is abit harder than the reductions which we have seen, but it exists.If you are interested, you can read it in the book Cormen,Leiserson, Rivest, Stein: Introduction to Algorithms.

Corollary: HAMILTONIAN and the decision version of the TSPare NP-complete.

Page 10: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

All of these decision problems are NP-complete:

I SATI 3-SATI CLIQUEI VERTEX COVERI HAMILTONIANI TSPI Many other decision problems.

If any of them is in P, then all of them are. Many people tried togive a polynomial time algorithm for them, but no one has beensuccessful so far. Therefore most people believe that P 6= NP.

Page 11: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

Relations between the classes which we have learnt

If we assume that P 6= NP, then the classes look like this:

P

NP−Complete

NP−Hard

NP

Page 12: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

What to do if our task is to solve an instance of a problem which isNP-hard?

There are many options:I If its size is small then we can use some exponential time

algorithms.

I If the problem is an optimization problem, then we can useheuristics or approximation algorithms.

I Check whether the given instance belongs to a specialversion of the problem which is not NP-complete, but it is inP.

Example: CNF-SAT is in NP-Complete, but 2-SAT is in P.Definition: A Boolean formula is 2-CNF if it is CNF and eachclause contains exactly two literals.

Problem 2-SATInput: A 2-CNF boolean formula φ.Question: Can φ be satisfied?

Page 13: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

What to do if our task is to solve an instance of a problem which isNP-hard?

There are many options:I If its size is small then we can use some exponential time

algorithms.I If the problem is an optimization problem, then we can use

heuristics or approximation algorithms.

I Check whether the given instance belongs to a specialversion of the problem which is not NP-complete, but it is inP.

Example: CNF-SAT is in NP-Complete, but 2-SAT is in P.Definition: A Boolean formula is 2-CNF if it is CNF and eachclause contains exactly two literals.

Problem 2-SATInput: A 2-CNF boolean formula φ.Question: Can φ be satisfied?

Page 14: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

What to do if our task is to solve an instance of a problem which isNP-hard?

There are many options:I If its size is small then we can use some exponential time

algorithms.I If the problem is an optimization problem, then we can use

heuristics or approximation algorithms.I Check whether the given instance belongs to a special

version of the problem which is not NP-complete, but it is inP.

Example: CNF-SAT is in NP-Complete, but 2-SAT is in P.Definition: A Boolean formula is 2-CNF if it is CNF and eachclause contains exactly two literals.

Problem 2-SATInput: A 2-CNF boolean formula φ.Question: Can φ be satisfied?

Page 15: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

2-SAT is in P

If an assignment of the variables makes the clause (l1 ∨ l2) trueand l1 = 0, then l2 must be 1. (In logic: (l1 ∨ l2) ⇐⇒ ¬l1 → l2)

We create a directed graph: The vertices of the graph are theliterals and the negated version of the literals which appears inthe formula. For each clause l1 ∨ l2 we add the directed edges~(¬l1, l2) and ~(¬l2, l1).

Example:

(x1 ∨ ¬x2) ∧ (x1 ∨ x2)∧∧(¬x1 ∨ ¬x2) ∧ (x1 ∨ x3) x3¬x1¬x2

x1 x2¬x3

If φ is satisfied and a literal l is true, then all other literals whichcan be reached from l by a directed path must be true.xi and ¬xi can not be both 1. So if φ is satisfied and there is adirected path from xi to ¬xi , then xi = 0. Similarly if there is adirected path from ¬xi to xi , then xi = 1.

Page 16: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

2-SAT is in P

If an assignment of the variables makes the clause (l1 ∨ l2) trueand l1 = 0, then l2 must be 1. (In logic: (l1 ∨ l2) ⇐⇒ ¬l1 → l2)We create a directed graph: The vertices of the graph are theliterals and the negated version of the literals which appears inthe formula. For each clause l1 ∨ l2 we add the directed edges~(¬l1, l2) and ~(¬l2, l1).

Example:

(x1 ∨ ¬x2) ∧ (x1 ∨ x2)∧∧(¬x1 ∨ ¬x2) ∧ (x1 ∨ x3) x3¬x1¬x2

x1 x2¬x3

If φ is satisfied and a literal l is true, then all other literals whichcan be reached from l by a directed path must be true.xi and ¬xi can not be both 1. So if φ is satisfied and there is adirected path from xi to ¬xi , then xi = 0. Similarly if there is adirected path from ¬xi to xi , then xi = 1.

Page 17: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

2-SAT is in P

So if there is a directed path from xi to ¬xi and also there isdirected path from ¬xi to xi for any variable xi , then φ can notbe satisfied. Otherwise there is an assignment of the variableswhich satisfies φ.

Example:

(x1 ∨ ¬x2) ∧ (x1 ∨ x2)∧∧(¬x1 ∨ ¬x2) ∧ (x1 ∨ x3) x3¬x1¬x2

x1 x2¬x3

We can check this condition by starting a BFS from each vertexand writing down whether there is a directed path from l to ¬l ,then we compare these. It requires O(n(n + e)) operations,where n is the number of vertices and e is the number of theedges. The number of the variables is n/2 and the number ofthe clauses are e/2, so this is polynomial in the size of φ. So2-SAT is in P.

Page 18: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

2-SAT is in P

So if there is a directed path from xi to ¬xi and also there isdirected path from ¬xi to xi for any variable xi , then φ can notbe satisfied. Otherwise there is an assignment of the variableswhich satisfies φ.

Example:

(x1 ∨ ¬x2) ∧ (x1 ∨ x2)∧∧(¬x1 ∨ ¬x2) ∧ (x1 ∨ x3) x3¬x1¬x2

x1 x2¬x3

We can check this condition by starting a BFS from each vertexand writing down whether there is a directed path from l to ¬l ,then we compare these. It requires O(n(n + e)) operations,where n is the number of vertices and e is the number of theedges. The number of the variables is n/2 and the number ofthe clauses are e/2, so this is polynomial in the size of φ. So2-SAT is in P.

Page 19: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

Why is this algorithm OK?If φ is satisfiable, then we can find a proper assignment of thevariables by using the rule that if there is a directed path from¬l to l , then l = 1.All such literals and every other literals which can be reachedfrom the later by a directed path are set to 1. We set theirnegates to 0. Similarly we set all literals to 1 if a directed pathleads from them to a literal whose value is 0. We set theirnegates to 1. We repeat these until we can.

(x1 ∨ ¬x2) ∧ (x1 ∨ x2)∧∧(¬x1 ∨ ¬x2) ∧ (x1 ∨ x3)

x3

¬x3

¬x2 = 1

x1 = 1 x2 = 0

¬x1 = 0

If some literals has not been set, then we choose one of them,set it to 1. We also set all the literals which can be reachedfrom it by a directed path to 1. We repeat it until all the literalsare set. No 1→ 0 edge appeared, so each clause is satisfied.

Page 20: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

Why is this algorithm OK?If φ is satisfiable, then we can find a proper assignment of thevariables by using the rule that if there is a directed path from¬l to l , then l = 1.All such literals and every other literals which can be reachedfrom the later by a directed path are set to 1. We set theirnegates to 0. Similarly we set all literals to 1 if a directed pathleads from them to a literal whose value is 0. We set theirnegates to 1. We repeat these until we can.

(x1 ∨ ¬x2) ∧ (x1 ∨ x2)∧∧(¬x1 ∨ ¬x2) ∧ (x1 ∨ x3)

¬x2 = 1

x1 = 1 x2 = 0

¬x1 = 0

¬x3 = 1

x3 = 0

If some literals has not been set, then we choose one of them,set it to 1. We also set all the literals which can be reachedfrom it by a directed path to 1. We repeat it until all the literalsare set. No 1→ 0 edge appeared, so each clause is satisfied.

Page 21: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

SUBSET SUM problem

We have seen many graph theoretical decision problems whichare NP-Complete. But there are many problems consistingnumbers or sets instead of graphs. To show that they areNP-complete we use SUBSET SUM as an intermediatedecision problem.

Problem SUBSET SUMInput: A list of integers a1,a2, . . . ,an and an integer t .Question: Is there a subset of the given integers such thattheir sum is t?Equivalently: Is there an I ⊆ [1,2, . . .n] such that

∑i∈I ai = t?

Example: Input: 1,2,3,4,6,10, t = 19.Answer:

Yes, because 3 + 6 + 10 = 19.

ClaimSUBSET SUM is NP-completeIt is easy to see that it is in NP.

Page 22: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

SUBSET SUM problem

We have seen many graph theoretical decision problems whichare NP-Complete. But there are many problems consistingnumbers or sets instead of graphs. To show that they areNP-complete we use SUBSET SUM as an intermediatedecision problem.

Problem SUBSET SUMInput: A list of integers a1,a2, . . . ,an and an integer t .Question: Is there a subset of the given integers such thattheir sum is t?Equivalently: Is there an I ⊆ [1,2, . . .n] such that

∑i∈I ai = t?

Example: Input: 1,2,3,4,6,10, t = 19.Answer: Yes, because 3 + 6 + 10 = 19.

ClaimSUBSET SUM is NP-completeIt is easy to see that it is in NP.

Page 23: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

SUBSET SUM problem

We have seen many graph theoretical decision problems whichare NP-Complete. But there are many problems consistingnumbers or sets instead of graphs. To show that they areNP-complete we use SUBSET SUM as an intermediatedecision problem.

Problem SUBSET SUMInput: A list of integers a1,a2, . . . ,an and an integer t .Question: Is there a subset of the given integers such thattheir sum is t?Equivalently: Is there an I ⊆ [1,2, . . .n] such that

∑i∈I ai = t?

Example: Input: 1,2,3,4,6,10, t = 19.Answer: Yes, because 3 + 6 + 10 = 19.

ClaimSUBSET SUM is NP-completeIt is easy to see that it is in NP.

Page 24: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

3SAT ≺ SUBSET SUMLet n be the number of variables and k the number of clauseswhich appears in input φ.For each variable xi we create two numbers ti and fi havingn + k digits, one of them will represent that the variable is true,and the other one is that the variable is false.The i th digit of ti and fi is 1. If xi appears in the j th clause (in anon negated form), then the n + j th digit of ti is 1.If ¬xi appears in the j th clause, then the n + j th digit of fi is 1.All other digits of ti and fi are zeros.(x1∨x2∨¬x3)∧ (¬x1∨¬x2∨x3)∧ (x1∨¬x2∨¬x3)∧ (x1∨x2∨x3)

Variables ClausesNumber x1 x2 x3 1 2 3 4

t1 1 0 0 1 0 1 1f1 1 0 0 0 1 0 0t2 0 1 0 1 0 0 1f2 0 1 0 0 1 1 0t3 0 0 1 0 1 0 1f3 0 0 1 1 0 1 0

Page 25: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

For each clause we create two numbers ci and ci which are thesame and their n + i th digit is 1 and the other digits of them are0.We have a target number t , whose first n (variable) digits are 1and the rest of the digits (clause) are 3.(x1∨x2∨¬x3)∧ (¬x1∨¬x2∨x3)∧ (x1∨¬x2∨¬x3)∧ (x1∨x2∨x3)

Variables ClausesNumber x1 x2 x3 1 2 3 4

c1 0 0 0 1 0 0 0c1 0 0 0 1 0 0 0c2 0 0 0 0 1 0 0c2 0 0 0 0 1 0 0c3 0 0 0 0 0 1 0c3 0 0 0 0 0 1 0c4 0 0 0 0 0 0 1c4 0 0 0 0 0 0 1t 1 1 1 3 3 3 3

Page 26: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

Example:

(x1 ∨ x2 ∨ ¬x3)∧∧(¬x1 ∨ ¬x2 ∨ x3)∧∧(x1 ∨ ¬x2 ∨ ¬x3)∧∧(x1 ∨ x2 ∨ x3)

A soultion:

x1 = 1

x2 = 0

x3 = 0

Variables ClausesNumber x1 x2 x3 1 2 3 4

t1 1 0 0 1 0 1 1f1 1 0 0 0 1 0 0t2 0 1 0 1 0 0 1f2 0 1 0 0 1 1 0t3 0 0 1 0 1 0 1f3 0 0 1 1 0 1 0c1 0 0 0 1 0 0 0c1 0 0 0 1 0 0 0c2 0 0 0 0 1 0 0c2 0 0 0 0 1 0 0c3 0 0 0 0 0 1 0c3 0 0 0 0 0 1 0c4 0 0 0 0 0 0 1c4 0 0 0 0 0 0 1t 1 1 1 3 3 3 3

Page 27: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

Example:

(x1 ∨ x2 ∨ ¬x3)∧∧(¬x1 ∨ ¬x2 ∨ x3)∧∧(x1 ∨ ¬x2 ∨ ¬x3)∧∧(x1 ∨ x2 ∨ x3)

A soultion:

x1 = 1

x2 = 0

x3 = 0

Variables ClausesNumber x1 x2 x3 1 2 3 4

t1 1 0 0 1 0 1 1f1 1 0 0 0 1 0 0t2 0 1 0 1 0 0 1f2 0 1 0 0 1 1 0t3 0 0 1 0 1 0 1f3 0 0 1 1 0 1 0c1 0 0 0 1 0 0 0c1 0 0 0 1 0 0 0c2 0 0 0 0 1 0 0c2 0 0 0 0 1 0 0c3 0 0 0 0 0 1 0c3 0 0 0 0 0 1 0c4 0 0 0 0 0 0 1c4 0 0 0 0 0 0 1t 1 1 1 3 3 3 3

Page 28: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

The correctness of the reduction:

If φ is satisfiable, then we choose the numbers correspondingto a proper assignment of the variables (either choose ti or fi ).The first n digits of their sum are all 1s. Each clause is satisfied,therefore the remaining k digits are at least one. For each j > 0we have 2 numbers whose n + j th digit is 1 and everything elseis 0. We use them to increase the n + j th digit of the sum to 3 ifit is needed. Finally we obtain t as a sum.

Assume that t is the sum of some of the constructed numbers.Since the first n digit of t is 1, either ti or fi but not both isincluded in the sum. So it has a corresponding assignment ofthe variables.Except cj and cj every other number whose n + j th digit is 1comes from ti or fi . Therefore one of them have to be includedin the sum, so at least one literal of the j th clause is true.

Page 29: NP-Completenes, Special caseslazsa/combopt2020spring/seventh_lecture_CO_20… · 3-SAT ˚CLIQUE For the input ˚= (l1 1 _l 1 2 _l 1 3)^(l2 1 _l 2 2 _l 2 3)^:::^(lk 1 _l k 2 _l k 3)

SUBSET SUM is NP-complete

Creating the numbers, ti , fi , ci , ci and t from φ can be done inpolynomial time. Therefore we have given a 3-SAT≺SUBSETSUM Karp reduction.SUBSET SUM is in NP and 3-SAT is NP-complete, thereforeSUBSET SUM is also NP-complete.

ClaimLet s =

∑ni=1 |ai |. There is an algortithm which solves SUBSET

SUM in O(ns) time.Corollray: If s is small, then in that special case we can solveSUBSET SUM efficiently.Note: s is big when we want to solve an input which weobtained by the 3-SAT≺ SUBSET SUM. So it does not lead to apolynomial time algorithm for 3-SAT.If you are interested in this algorithm then search for dinamicprogramming.