0% found this document useful (0 votes)
12 views

Algorithmique Npcompleteness 2011c

This document discusses algorithms and complexity classes such as P and NP. It defines key concepts like decision problems, input size, polynomial time, and the class P of problems solvable by a polynomial-time algorithm. Several example problems are given, like CONNECTIVITY and FLOW, which are in P, while the complexity of CLIQUE and INDEPENDENT SET are unknown. The document notes that the theory of NP-completeness aims to understand why some problems like these may not have efficient algorithms.

Uploaded by

Mardig Hagopian
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Algorithmique Npcompleteness 2011c

This document discusses algorithms and complexity classes such as P and NP. It defines key concepts like decision problems, input size, polynomial time, and the class P of problems solvable by a polynomial-time algorithm. Several example problems are given, like CONNECTIVITY and FLOW, which are in P, while the complexity of CLIQUE and INDEPENDENT SET are unknown. The document notes that the theory of NP-completeness aims to understand why some problems like these may not have efficient algorithms.

Uploaded by

Mardig Hagopian
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 99

NP-Completeness

Algorithmique
Fall semester 2011/12

1
What is an Algorithm?

We haven’t really answered this question in this course.

Informally, an algorithm is a step-by-step procedure for computing a set of outputs


from a set of inputs.

But formally, to define what an algorithm is, we need to concept of a Turing Machine.

This cannot be developed fully in this course, and is typically part of a course in Theoretical
Computer Science.

Will work with the informal concept instead.

2
Turing Machine

Bare bone abstraction of a computer.

Consists of
• Input/Output alphabet (0-1)
• Infinite tape (memory)
• Read/Write head (I/O)
• Control (program) Alan Turing, 1912-1954

0 1 1 0 0 1 0 1 0 1 1 1 0 0 1 0 1 0

Upon reading tape, and consulting internal state,


Control decides what to write on tape, what to do with the
head (left/right/stay), and how to change internal
state

3
Dictionary

Turing machine Computer

Alphabet 0-1 Suited for electronic circuits

Tape Memory

Read/Write head I/O

Control Program

State Program variables

# head movements “Running time”

# cells visited Space requirement

4
Turing Machines

Turing machines provide a very good abstraction of the notion of computing, and a framework for
studying the complexity of computational problems.

They lie at the heart of the theory of NP-completeness, which we are going to discuss in this class.

However, for time reasons we will not be able to use them. Instead, we rely on an intuitive
concept of an algorithm and its running time (as the number of “operations” they use).

5
Computational Problem

Example

I Set of inputs I = set of graphs

O = {true,false}
O Set of outputs
(G,true) in R iff G is connected

(G,false) in R iff G is not connected


R⊆I ×O Relational dependency

Computational problem: Example

Given G, decide whether it is


Given ι ∈ I, find ω ∈ O, such that (ι, ω) ∈ R connected.

6
Decision Problem

O = {true, false}
I
R⊆I ×O

R is equivalent to subset of I mapping to true. true false

R is equivalent to this
part

7
Examples

I=N 170141183460469231731687303715884105727 is in R

R = {n ∈ I | n is prime} 10384593717069655257060992658440191 is not in R

I = set of graphs × N
(G,3) is not in R
G=
R = {(G, n) | G has an independent set of size ≥ n} (G,2) is in R
Independent set
Set of vertices no two of which
are connected

I = set of graphs × N (G,4) is not in R


G=
R = {(G, n) | G has a clique of size ≥ n} (G,3) is in R

Clique
Set of vertices any two of
which are connected

8
Algorithms for Decision Problems

An algorithm for a decision problem R ⊆ I is an algorithm which for every input ι ∈ I


decides whether ι ∈ R

Example

R = set of all connected graphs

Decision problem: given G, decide whether it is connected

Algorithm: DFS

Example

R = set of all prime numbers

Decision problem: given n, decide whether it is prime

Algorithm: primality testing

Example

R = {(G,n) | G graph, n integer, G has an independent set of size ≥ n}

Decision problem: decide whether G has independent set of size at least n

Algorithm: ?????

9
Input Lengths

The length |ι| of an input ι ∈ I is the number of bits sufficient to represent it.

Example

G graph on n vertices, |G| = O(n2)

To represent G, we need n, and a list of n2 bits representing the adjacency matrix of G

Example

n integer, |n| = O(log(n))

Need O(log(n)) bits to write down n

10
Polynomial Functions

A function f : N → N is said to be polynomial in g : N → N if there is a a polynomial p such


that f(n) = O(p(g(n)))

Examples

• f(n)=n is polynomial in g(n) = n2


• f(n) = n3 is polynomial in g(n) = n
• Any polynomial is polynomial in the function f(n) = n (identity function)
• The identity function is polynomial in any polynomial function
• The function f(n) = 2n is not polynomial in the identity function

11
The Class P

Class of all decision problems R ⊆ I for which there is an algorithm which decides for every
given ι ∈ I whether ι ∈ R and for which the running time is polynomial in |ι|

Example

CONNECTIVITY = {G | G is a connected graph}

CONNECTIVITY is in P (Running time of DFS is polynomial in number of vertices)

Example

I = {(G,s,t,c,M) | G directed graph, c:E -> N integer capacities, s,t distinct vertices, M integer}

FLOW = {(G,s,t,c,M) | G has an s-t flow of value at least M}

FLOW is in P:

• Size of input on n vertices is ϴ(n2 log(C)+log(M)) where C is max capacity

• The algorithm of Ford and Fulkerson with BFS shortest path selection has running time
polynomial in the input size.

P is the class of all decision problems for which there is a polynomial time decision algorithm.

12
Why Polynomial Time?

Captures the notion of “efficiency”


Is robust with respect to common theoretical transformations

13
The Class P

PRIMALITY = {n | n is a prime number}

PRIMALITY is in P ?

CLIQUE = {(G,n) | G has a clique of size at least n}

CLIQUE is in P ?

INDEP-SET = {(G,n) | G has an independent set of size at least n}

INDEP-SET is in P ?

14
The Class P

PRIMALITY = {n | n is a prime number}

PRIMALITY is in P ? Yes, but not via the naive algorithm

CLIQUE = {(G,n) | G has a clique of size at least n}

CLIQUE is in P ? Unknown

INDEP-SET = {(G,n) | G has an independent set of size at least n}

INDEP-SET is in P ? Unknown

15
NP Completeness

Theory of NP-completeness tries to understand why we have not been able to find
polynomial time algorithms for some fundamental computational problems.

Its main assertions are of the following type:

If you could solve problem X in polynomial time, then could solve a whole lot of other very
hard problems in polynomial time as well.

To some researchers, it means that there are no polynomial time algorithms for such
problems.

16
Polynomial Reduction

We want to capture the following notion:

If we can solve decision problem X, then we can also solve decision problem Y using an
algorithm for the solution of problem X. We want to reduce Y to X

How can we use an algorithm for problem X for inputs for problem Y?

We need to transform an input y for problem Y to a valid input x for problem X


Then we apply the algorithm for X to this new input x

If the output of the algorithm is true, then we want to deduce that y belongs to Y
If the output of the algorithm is false, then we want to deduce that y doesn’t belong to Y

We want all this to be efficient, so the transformation of y to x should be efficiently


computable.
17
Polynomial Reduction

X ⊆ I, Y ⊆ J decision problems.

A polynomial reduction from Y to X is a function f : J → I such that


• for all y in J, f(y) is in X iff y is in Y
• There is an algorithm which computes f(y) for any y in Y with a number of steps
polynomial in |y|.

In this case, we write Y ≤P X or Y ≤ X

18
Polynomial Reduction

true false

False instances of Y should be


True instances of Y should be Transformation has to be efficient
mapped to false instances of X
mapped to true instances of X

true false

X
19
Example

CLIQUE ≤ INDEP-SET

(G,m) input to CLIQUE


H complement of G: G Clique

• if there is no edge between u,v, add (u,v) to the edges of H


• If there is an edge between (u,v) in G, don’t put that edge in H
f: (G,m) -> (H,m) is the reduction true only for general graphs.

f can be calculated in time polynomial in n, which is polynomial in |(G,m)| = O(n2+log(m))


H Independent
f(G,m) in INDEP-SET iff (H,m) in INDEP-SET iff there are m nodes in H no two of which are
connected, iff there are m nodes in G any two of which are connected, iff (G,m) in CLIQUE

INDEP-SET ≤ CLIQUE
Same reasoning as above

Testing membership to INDEP-SET is “as difficult” as testing membership to “CLIQUE”

20
Example

A node cover in a graph is a set S of vertices such that every edge has at least one endpoint
in S.

NODE-COVER = {(G,m) | G has a node cover with at most m elements}

(G,3) is not in NODE-COVER


G=
(G,4) is in NODE-COVER

INDEP-SET ≤ NODE-COVER

(G,m) input to INDEP-SET Independent


f: (G,m) -> (G,n-m) is the reduction where n is number of vertices of G
f can be calculated in time polynomial in the input G
f(G,m) in NODE-COVER iff (G,n-m) in NODE-COVER iff there are n-m nodes in G such that any
edge has at least one endpoint in this set iff any two nodes outside this set are not connected
iff (G,m) is in INDEP-SET Node cover

NODE-COVER ≤ INDEP-SET similar to the above

21
Transitivity

X ≤ Y and Y ≤ Z =⇒ X ≤ Z

Suppose that f is a reduction from X to Y, so a is in X iff f(a) is in Y


Suppose that g is a reduction from Y to Z, so b is in Y iff g(b) is in Z
Let h(a) = g(f(a)).
a is in x iff f(a) is in Y iff g(f(a)) is in Z.
h can be computed efficiently, since g and f can.
So, h is a polynomial reduction from X to Z.

22
The Class NP

Some decision problems, like NODE-COVER and INDEPENDENT-SET have defied


attempts at finding efficient decision algorithms.

However, these problems have an interesting feature: while it may be difficult to decide for
every input whether it belongs to these sets, it is rather easy to prove the claim that an input
belongs to these sets.

23
Examples

COMPOSITES = {n | n is not prime}

239180344702445517659253489067517158015016827169517973733973209 is in COMPOSITES!

You don’t need to factor the number to see that I am right: I provide you with a “short” proof:

239180344702445517659253489067517158015016827169517973733973209 =

15465456498352886242205023347881 * 15465456498352886242205023347889

You just need to perform the multiplication to get convinced (which is much easier than
factoring the integer).

(G,10) is in INDEP-SET

Finding an independent set of size 10


G= may be difficult.

24
Examples

COMPOSITES = {n | n is not prime}

239180344702445517659253489067517158015016827169517973733973209 is in COMPOSITES!

You don’t need to factor the number to see that I am right: I provide you with a “short” proof:

239180344702445517659253489067517158015016827169517973733973209 =

15465456498352886242205023347881 * 15465456498352886242205023347889

You just need to perform the multiplication to get convinced (which is much easier than
factoring the integer).

(G,10) is in INDEP-SET

Finding an independent set of size 10


G= may be difficult.

But proving that I have one is simple.

25
The Class NP
Decision problems in the class NP are problems R for which there is an efficient proof of
membership to R.

There is a function f : I×{0,1}* " {true,false} such that


R = { c | f(c,w)=true for some string w}
and f(c,w) can be calculated in time polynomial in |c|. f is called a verifier, and w is called a
witness of membership of c to R.

26
Closed under Polynomial Reductions

If X is in NP, and Y ≤ X , then Y is in NP as well.


Use reduction f from Y to X.
Take any input a from the set of inputs of Y.
Transform via f -> f(a)
There is witness w and poly-time function g such that g(f(a),w)=1 if f(a) is in X
w is a witness for a, g together with f is a verifier.

27
Includes P

P is a subset of NP
Suppose that R is in P, and that f is a poly-time algorithm for R.
Given a, the witness w is empty, and the verifier is f itself: note that f(a)=1 iff a is in R.

NP

Are P and NP equal?


Million dollar question.....
P

World according to some (top) researchers

28
Examples

INDEP-SET ∈ NP

(G,10) is in INDEP-SET

The witness is a set of 10 or more


vertices.
G=
The verifier checks whether none of
these vertices are connected.

The verifier can do this in time


polynomial in the length of the graph.

NODE-COVER ≤ INDEP-SET =⇒ NODE-COVER ∈ NP

CLIQUE ≤ INDEP-SET =⇒ CLIQUE ∈ NP

29
Examples

COMPOSITES ∈ NP

COMPOSITES = {n | n is not prime}

239180344702445517659253489067517158015016827169517973733973209 is in COMPOSITES!

The witness consists of two integers larger than 1

15465456498352886242205023347881 , 15465456498352886242205023347889

The verifier multiplies these numbers and checks whether the result is the original number

The verifier can perform this task in time polynomial in the number of digits of the original
number (using the school method)

30
PRIMES

PRIMES ∈ NP?

Given an integer n, how can I convince you that it is prime?

What is a witness of primality? What is the verifier?

What is NOT a verifier is an algorithm that checks all the potential divisors of n.

This is because this algorithm runs in time proportional to sqrt(n), which is NOT polynomial in
the input length |n| = O(log(n)).

What can be done?

31
Elementary Number Theory

p is prime if and only if there is an integer w such that

w(p-1)/p1 , w(p-1)/p2 , ......., w(p-1)/pk is not 1 modulo p, where

p1, p2, ..., pk are all the prime divisors of p-1

Not difficult, but without proof.

“Witness” for the primality of p:


w, and p1,....,pk.
Steps for verifying primality of p:
• Check that p1,....,pk are all prime The primality of these has to be proved recursively

• Check that p1,....,pk are all the prime divisors of p-1 Easy to do (division)
• Check that w(p−1)/p1 , . . . , w(p−1)/pk �≡ 1 mod p Easy to do (binary method of exponentiation)

Witness is a tree with node labels (called the Pratt tree)

Verifier processes the tree to obtain proof of primality

Vaughan Pratt, 1944 -

32
Example: Pratt Tree
n w
1223, 5

2, 1 47, 5 13, 2

23, 5 2, 1 2, 1 3, 2

11, 2 2, 1 2, 1

2, 1 5, 2
Process the tree
from bottom to top

2, 1

Pratt tree proving that 1223 is prime

33
Example: Pratt Tree

1223, 5

2, 1 47, 5 13, 2

23, 5 2, 1 2, 1 3, 2

11, 2 2, 1 2, 1

2, 1 5, 2

2, 1 prime

Pratt tree proving that 1223 is prime

34
Example: Pratt Tree

1223, 5

2, 1 47, 5 13, 2

23, 5 2, 1 2, 1 3, 2

11, 2 2, 1 2, 1

prime 2, 1 5, 2 5-1=22, 22 = 1 mod 5, so 5 prime

2, 1 prime

Pratt tree proving that 1223 is prime

35
Example: Pratt Tree

1223, 5

2, 1 47, 5 13, 2

23, 5 2, 1 2, 1 3, 2

11-1=2 x 5,
22 = 1 mod 11, 25 = 1 mod 11 11, 2 2, 1 prime 2, 1 prime
So 11 is prime

prime 2, 1 5, 2 5-1=22, 22 = 1 mod 5, so 5 prime

2, 1 prime

Pratt tree proving that 1223 is prime

36
Example: Pratt Tree

1223, 5

2, 1 47, 5 13, 2

23-1=2 x 11,
3-1=2, 2 = 1 mod 3,
52 = 1 mod 23, 511 = 1 mod 23 23, 5 2, 1 prime 2, 1 3, 2
so 3 prime
So 23 is prime

11-1=2 x 5,
22 = 1 mod 11, 25 = 1 mod 11 11, 2 2, 1 prime 2, 1 prime
So 11 is prime

prime 2, 1 5, 2 5-1=22, 22 = 1 mod 5, so 5 prime

2, 1 prime

Pratt tree proving that 1223 is prime

37
Example: Pratt Tree

1223, 5

47-1=2 x 23, 13-1=2 x 6,


52 = 1 mod 47, 22 = 1 mod 13,
prime 2, 1 47, 5 23 13, 2 6
5 = 1 mod 47 2 = 1 mod 13
So 47 is prime So 13 is prime
23-1=2 x 11,
3-1=2, 2 = 1 mod 3,
52 = 1 mod 23, 511 = 1 mod 23 23, 5 2, 1 prime 2, 1 3, 2
so 3 prime
So 23 is prime

11-1=2 x 5,
22 = 1 mod 11, 25 = 1 mod 11 11, 2 2, 1 prime 2, 1 prime
So 11 is prime

prime 2, 1 5, 2 5-1=22, 22 = 1 mod 5, so 5 prime

2, 1 prime

Pratt tree proving that 1223 is prime

38
Example: Pratt Tree
1223-1=2 x 13 x 47,
1223, 5 5611 = 1 mod 1223, 594 = 1 mod 1223,
526 = 1 mod 1223, so 1223 is prime

47-1=2 x 23, 13-1=2 x 6,


52 = 1 mod 47, 22 = 1 mod 13,
prime 2, 1 47, 5 23 13, 2 6
5 = 1 mod 47 2 = 1 mod 13
So 47 is prime So 13 is prime
23-1=2 x 11,
3-1=2, 2 = 1 mod 3,
52 = 1 mod 23, 511 = 1 mod 23 23, 5 2, 1 prime 2, 1 3, 2
so 3 prime
So 23 is prime

11-1=2 x 5,
22 = 1 mod 11, 25 = 1 mod 11 11, 2 2, 1 prime 2, 1 prime
So 11 is prime

prime 2, 1 5, 2 5-1=22, 22 = 1 mod 5, so 5 prime

2, 1 prime

Pratt tree proving that 1223 is prime

39
PRIMES in NP

Careful analysis shows that:


• Pratt tree has size polynomial in |n| = O(log(n))
• Verification can be done in time polynomial in log(n).

PRIMES ∈ NP

40
NP-Completeness

A decision problem R is called NP-complete if


• R is in NP
• For any problem X in NP there is a reduction from X to R: X ≤ R
Is this an empty definition?

It is not at all clear that such a problem even exists.

Such a problem is a hardest problem in NP (if you can solve it efficiently, then you can solve
any problem in NP efficiently)

Do such problems exist?

41
A Little Logic

A boolean variable x is a variable that can take values in the set {false,true} (or {0,1})
From boolean variables x and y we can obtain new variables via logical operations

x y ¬x x∨y x∧y

0 0 1 0 0

0 1 1 1 0

1 0 0 1 0

1 1 0 1 1

¬x = not x

x ∨ y = x or y

x ∧ y = x and y

42
Literals, Clauses, Formulas
Examples

Variable x1 , x2 , . . . , xn x1 , x3 , . . .

Literal λ ∈ {x1 , . . . , xn , ¬x1 , . . . , ¬xn } ¬x5 , x10 , ¬x220 , . . .

Clause C = λ1 ∨ λ 2 ∨ · · · ∨ λ t x1 ∨ ¬x3 ∨ ¬x10 ∨ x4

Formula F = C1 ∧ C2 ∧ · · · ∧ C� (x1 ∨ ¬x3 ∨ ¬x10 ∨ x4 ) ∧ (x2 ∨ x5 ∨ x9 ) ∧ (¬x6 ∨ x8 )

43
Length of a Formula

x10 " 0.1010 Bit representation of 10 - The first “0.” is to say that the literal is not negated.

¬x5 " 1.101 Bit representation of 5 - The first “1.” is to say that the literal is negated.

x1 ∨ ¬x3 ∨ ¬x10 ∨ x4 " 0.1*1.11*1.10101*0.100 “*” indicates the OR operation

(x1∨¬x3∨¬x10∨x4) (x2∨x5∨x9)∧(¬x6∨x8) "


“|” indicates the AND operation
0.1*1.11*1.10101*0.100|0.10*0.101*0.1001|1.110*0.100

With n variables, length of formula is proportional to log(n) x number of literals

44
Satisfiability Problem

Formula F is called satisfiable if there is a setting of the variables that makes the formula
evaluate to “true” (or 1).
Such a setting of the variables is called a satisfying assignment.

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


has satisfying assignment
(x1,x2,x3,x4)=(0,0,0,1)

Checking whether a formula is satisfiable can be hard: there may be only 1 satisfying assignment (out of
the 2n possible).

The difference between this and 0 satisfying assignments is “very small”.

45
Satisfiability Problem

SAT = { F | F satisfiable formula } is called the satisfiability problem

Associated computational problem: given F, check whether it is satisfiable.

SAT is in NP: “witness” for a satisfiable formula is a satisfying assignment.


Formula can be evaluated at the given assignment in time polynomial in
length of the formula.

46
The Cook-Levin Theorem

Leonid Levin, 1948 -

Stephen Cook, 1939 -

SAT is NP-complete.

If you can find an polynomial time algorithm for solving SAT, then you can solve other hard problems, like
for example factoring integers, finding large independent sets, cliques, node covers, etc.

47
Are there Other NP-Complete Problems?

Many more than you might think....

k-clause: clause with exactly k literals


k-formula: formula in which every clause is a k-clause

k-SAT = { F | F is a satisfiable k formula }

Theorem: k-SAT is NP-complete for k larger than 2.

48
Example: 3-SAT

How do we prove that 3-SAT is NP-complete?

Step 1: Show that 3-SAT is in NP It better; otherwise it cannot be NP-complete

Step 2: Show that SAT ≤ 3-SAT For X in NP, we have X ≤ SAT ≤ 3-SAT, so X ≤ 3-SAT.

3-SAT is in NP: witness is satisfying assignment.

SAT ≤ 3-SAT: Need to find polynomial reduction from SAT to 3-SAT

49
Reduction of SAT to 3-SAT

Transform a formula F into a 3-formula G such that F is satisfiable iff G is.


Will do this clause-by-clause. Here an example when clause has ≥ 3 literals.

C = (x1 ∨ x5 ∨ ¬x6 ∨ x7 ∨ x8 ∨ x12) Original clause


Introduce new variable,
F1 = (x1 ∨ x5 ∨ ¬x6 ∨ x7 ∨ ¬y1) ∧ (y1 ∨ x8 ∨ x12) take last two literals, and
make new formula
F1 is satisfiable iff C is:
C satisfiable set y1=0 is x8 or x12 are 1, else set y1=1 F1 satisfiable
F1 satisfiable: if y1=0, then x1 or x12 are 1, else one of the other literals is 1 C is satisfiable

50
Reduction of SAT to 3-SAT

Transform a formula F into a 3-formula G such that F is satisfiable iff G is.


Will do this clause-by-clause. Here an example when clause has ≥ 3 literals.

C = (x1 ∨ x5 ∨ ¬x6 ∨ x7 ∨ x8 ∨ x12) Original clause


Introduce new variable,
F1 = (x1 ∨ x5 ∨ ¬x6 ∨ x7 ∨ ¬y1) ∧ (y1 ∨ x8 ∨ x12) take last two literals, and
make new formula
F1 is satisfiable iff C is:
C satisfiable set y1=0 is x8 or x12 are 1, else set y1=1 F1 satisfiable
F1 satisfiable: if y1=0, then x1 or x12 are 1, else one of the other literals is 1 C is satisfiable

F2 = (x1 ∨ x5 ∨ ¬x6 ∨ ¬y2) ∧ (y2 ∨ x7 ∨ ¬y1) ∧ (y1 ∨ x8 ∨ x12) Repeat process

51
Reduction of SAT to 3-SAT

Transform a formula F into a 3-formula G such that F is satisfiable iff G is.


Will do this clause-by-clause. Here an example when clause has ≥ 3 literals.

C = (x1 ∨ x5 ∨ ¬x6 ∨ x7 ∨ x8 ∨ x12) Original clause


Introduce new variable,
F1 = (x1 ∨ x5 ∨ ¬x6 ∨ x7 ∨ ¬y1) ∧ (y1 ∨ x8 ∨ x12) take last two literals, and
make new formula
F1 is satisfiable iff C is:
C satisfiable set y1=0 is x8 or x12 are 1, else set y1=1 F1 satisfiable
F1 satisfiable: if y1=0, then x1 or x12 are 1, else one of the other literals is 1 C is satisfiable

F2 = (x1 ∨ x5 ∨ ¬x6 ∨ ¬y2) ∧ (y2 ∨ x7 ∨ ¬y1) ∧ (y1 ∨ x8 ∨ x12) Repeat process

F3 = (x1 ∨ x5 ∨ ¬y3) ∧ (y3 ¬x6 ∨ ¬y2) ∧ (y2 ∨ x7 ∨ ¬y1) ∧ (y1 ∨ x8 ∨ x12)


F3 is now a 3-formula which is satisfiable iff C is

52
Reduction of SAT to 3-SAT

Transform a formula F into a 3-formula G such that F is satisfiable iff G is.


Will do this clause-by-clause. Here an example when clause has ≥ 3 literals.

C = (x1 ∨ x5 ∨ ¬x6 ∨ x7 ∨ x8 ∨ x12) Original clause


Introduce new variable,
F1 = (x1 ∨ x5 ∨ ¬x6 ∨ x7 ∨ ¬y1) ∧ (y1 ∨ x8 ∨ x12) take last two literals, and
make new formula
F1 is satisfiable iff C is:
C satisfiable set y1=0 is x8 or x12 are 1, else set y1=1 F1 satisfiable
F1 satisfiable: if y1=0, then x1 or x12 are 1, else one of the other literals is 1 C is satisfiable

F2 = (x1 ∨ x5 ∨ ¬x6 ∨ ¬y2) ∧ (y2 ∨ x7 ∨ ¬y1) ∧ (y1 ∨ x8 ∨ x12) Repeat process

F3 = (x1 ∨ x5 ∨ ¬y3) ∧ (y3 ¬x6 ∨ ¬y2) ∧ (y2 ∨ x7 ∨ ¬y1) ∧ (y1 ∨ x8 ∨ x12)


F3 is now a 3-formula which is satisfiable iff C is

Repeat this process for all the clauses.


Each clause with l ≥ 3 literals becomes formula with l-2 clauses and l-3 new
variables.
Size of new formula is polynomial in size of old. Valid polynomial reduction.

53
Reduction of SAT to 3-SAT

Clauses with 1 or 2 literals:


C = (x1 ∨ x5) $ (x1 ∨ x5 ∨ ¬y1) ∧ (y1 ∨ x1 ∨ x5)

C = ¬x10 $ (¬x10 ∨ ¬y1) ∧ (y1 ∨ ¬x10) Now reduce to previous case

Method works also for k-SAT, k ≥ 3.

What about 2-SAT? It turns out that it is in P. Without proof.

54
MAX-2-SAT

2-SAT is in P.
But if a 2-formula is not satisfiable, can we efficiently find the maximum number of
satisfiable clauses in the formula?

F is a 1-2-formula if all clauses in F have at most 2 literals.

MAX-2-SAT = {(F,m) | F 1-2-formula for which there is an assignment satisfying ≥ m


clauses}

G = x ∧ y ∧ z ∧ w ∧ (¬x ∨ ¬y) ∧ (¬y ∨ ¬z) ∧ (¬x ∨ ¬z) ∧ (x ∨ ¬w) ∧ (y ∨ ¬w) ∧ (z ∨ ¬w)

(G,7) is in MAX-2-SAT: x= 0, y = 0, z = 1, w = 0 satisfies the 7 clauses


z, (¬x ∨ ¬y) , (¬y ∨ ¬z) , (¬x ∨ ¬z) , (x ∨ ¬w) , (y ∨ ¬w) , (z ∨ ¬w)

Theorem:
• If (x ∨ y ∨ z) = 1, then there is assignment for w such that 7 clauses of G are satisfied.
• If (x ∨ y ∨ z) = 0, then no matter how w is chosen, at most 6 clauses of G are satisfied.

So, (G,8) is not in MAX-2-SAT.

55
MAX-2-SAT
If x∨y∨z = 1, then w can be chosen such that exactly seven of the other clauses are 1.

x y z w ¬x ∨ ¬y ¬z ∨ ¬y ¬x ∨ ¬z x ∨ ¬w y ∨ ¬w z ∨ ¬w x∨y∨z
0 0 0 0 1 1 1 1 1 1 0
0 0 0 1 1 1 1 0 0 0 0
0 0 1 0 1 1 1 1 1 1 1
0 0 1 1 1 1 1 0 0 1 1
0 1 0 0 1 1 1 1 1 1 1
0 1 0 1 1 1 1 0 1 0 1
0 1 1 0 1 0 1 1 1 1 1
0 1 1 1 1 0 1 0 1 1 1
1 0 0 0 1 1 1 1 1 1 1
1 0 0 1 1 1 1 1 0 0 1
1 0 1 0 1 1 0 1 1 1 1
1 0 1 1 1 1 0 1 0 1 1
1 1 0 0 0 1 1 1 1 1 1
1 1 0 1 0 1 1 1 1 0 1
1 1 1 0 0 0 0 1 1 1 1
1 1 1 1 0 0 0 1 1 1 1

56
MAX-2-SAT
If x∨y∨z = 1, then w can be chosen such that exactly seven of the other clauses are 1.

x y z w ¬x ∨ ¬y ¬z ∨ ¬y ¬x ∨ ¬z x ∨ ¬w y ∨ ¬w z ∨ ¬w x∨y∨z
0 0 0 0 1 1 1 1 1 1 0
0 0 0 1 1 1 1 0 0 0 0
0 0 1 0 1 1 1 1 1 1 1
0 0 1 1 1 1 1 0 0 1 1
0 1 0 0 1 1 1 1 1 1 1
0 1 0 1 1 1 1 0 1 0 1
0 1 1 0 1 0 1 1 1 1 1
0 1 1 1 1 0 1 0 1 1 1
1 0 0 0 1 1 1 1 1 1 1
1 0 0 1 1 1 1 1 0 0 1
1 0 1 0 1 1 0 1 1 1 1
1 0 1 1 1 1 0 1 0 1 1
1 1 0 0 0 1 1 1 1 1 1
1 1 0 1 0 1 1 1 1 0 1
1 1 1 0 0 0 0 1 1 1 1
1 1 1 1 0 0 0 1 1 1 1

57
MAX-2-SAT
If x∨y∨z = 1, then w can be chosen such that exactly seven of the other clauses are 1.

x y z w ¬x ∨ ¬y ¬z ∨ ¬y ¬x ∨ ¬z x ∨ ¬w y ∨ ¬w z ∨ ¬w x∨y∨z
0 0 0 0 1 1 1 1 1 1 0
0 0 0 1 1 1 1 0 0 0 0
0 0 1 0 1 1 1 1 1 1 1
0 0 1 1 1 1 1 0 0 1 1 Choose w = 0
0 1 0 0 1 1 1 1 1 1 1
0 1 0 1 1 1 1 0 1 0 1
0 1 1 0 1 0 1 1 1 1 1
0 1 1 1 1 0 1 0 1 1 1
1 0 0 0 1 1 1 1 1 1 1
1 0 0 1 1 1 1 1 0 0 1
1 0 1 0 1 1 0 1 1 1 1
1 0 1 1 1 1 0 1 0 1 1
1 1 0 0 0 1 1 1 1 1 1
1 1 0 1 0 1 1 1 1 0 1
1 1 1 0 0 0 0 1 1 1 1
1 1 1 1 0 0 0 1 1 1 1

58
MAX-2-SAT
If x∨y∨z = 1, then w can be chosen such that exactly seven of the other clauses are 1.

x y z w ¬x ∨ ¬y ¬z ∨ ¬y ¬x ∨ ¬z x ∨ ¬w y ∨ ¬w z ∨ ¬w x∨y∨z
0 0 0 0 1 1 1 1 1 1 0
0 0 0 1 1 1 1 0 0 0 0
0 0 1 0 1 1 1 1 1 1 1
0 0 1 1 1 1 1 0 0 1 1
0 1 0 0 1 1 1 1 1 1 1
0 1 0 1 1 1 1 0 1 0 1
0 1 1 0 1 0 1 1 1 1 1
0 1 1 1 1 0 1 0 1 1 1
1 0 0 0 1 1 1 1 1 1 1
1 0 0 1 1 1 1 1 0 0 1
1 0 1 0 1 1 0 1 1 1 1
1 0 1 1 1 1 0 1 0 1 1
1 1 0 0 0 1 1 1 1 1 1
1 1 0 1 0 1 1 1 1 0 1
1 1 1 0 0 0 0 1 1 1 1
1 1 1 1 0 0 0 1 1 1 1

59
MAX-2-SAT
If x∨y∨z = 0, then no matter how we choose w, at most six of the clauses are 1.

x y z w ¬x ∨ ¬y ¬z ∨ ¬y ¬x ∨ ¬z x ∨ ¬w y ∨ ¬w z ∨ ¬w x∨y∨z
0 0 0 0 1 1 1 1 1 1 0
0 0 0 1 1 1 1 0 0 0 0
0 0 1 0 1 1 1 1 1 1 1
0 0 1 1 1 1 1 0 0 1 1
0 1 0 0 1 1 1 1 1 1 1
0 1 0 1 1 1 1 0 1 0 1
0 1 1 0 1 0 1 1 1 1 1
0 1 1 1 1 0 1 0 1 1 1
1 0 0 0 1 1 1 1 1 1 1
1 0 0 1 1 1 1 1 0 0 1
1 0 1 0 1 1 0 1 1 1 1
1 0 1 1 1 1 0 1 0 1 1
1 1 0 0 0 1 1 1 1 1 1
1 1 0 1 0 1 1 1 1 0 1
1 1 1 0 0 0 0 1 1 1 1
1 1 1 1 0 0 0 1 1 1 1

60
MAX-2-SAT is NP-Complete

Will first show that MAX-2-SAT is in NP.


The witness is a satisfying assignment: for every clause, we check whether the clause is satisfied
and keep track of the number of satisfied clauses. We check whether this number is ≥ m.

61
MAX-2-SAT is NP-Complete

Will first show that MAX-2-SAT is in NP.


The witness is a satisfying assignment: for every clause, we check whether the clause is satisfied
and keep track of the number of satisfied clauses. We check whether this number is ≥ m.

Next, we show that 3-SAT ≤ MAX-2-SAT.


F = C1 ∧ C2 ∧ ∧ Cm 3-formula. Will transform it into (H,7m) where H is a 1-2-formula such that
F is satisfiable iff (H,7m) is in MAX-2-SAT, i.e., there is assignment satisfying ≥ 7m clauses of H.

62
MAX-2-SAT is NP-Complete

Will first show that MAX-2-SAT is in NP.


The witness is a satisfying assignment: for every clause, we check whether the clause is satisfied
and keep track of the number of satisfied clauses. We check whether this number is ≥ m.

Next, we show that 3-SAT ≤ MAX-2-SAT.


F = C1 ∧ C2 ∧ ∧ Cm 3-formula. Will transform it into (H,7m) where H is a 1-2-formula such that
F is satisfiable iff (H,7m) is in MAX-2-SAT, i.e., there is assignment satisfying ≥ 7m clauses of H.

Introduce new variables w1,..., wm.


Cj = λ1 ∨ λ2 ∨ λ3 $
Dj = λ1 ∧ λ2 ∧ λ3 ∧ wj ∧ (¬λ1∨¬λ2) ∧ (¬λ2∨¬λ3) ∧ (¬λ1∨¬λ3) ∧ (λ1∨¬wj) ∧ (λ2∨¬wj) ∧ (λ3∨¬wj)
H = D 1 ∧ D2 ∧ ∧ Dm (10m clauses)
Transformation is poly-time.

63
MAX-2-SAT is NP-Complete

Will first show that MAX-2-SAT is in NP.


The witness is a satisfying assignment: for every clause, we check whether the clause is satisfied
and keep track of the number of satisfied clauses. We check whether this number is ≥ m.

Next, we show that 3-SAT ≤ MAX-2-SAT.


F = C1 ∧ C2 ∧ ∧ Cm 3-formula. Will transform it into (H,7m) where H is a 1-2-formula such that
F is satisfiable iff (H,7m) is in MAX-2-SAT, i.e., there is assignment satisfying ≥ 7m clauses of H.

Introduce new variables w1,..., wm.


Cj = λ1 ∨ λ2 ∨ λ3 $
Dj = λ1 ∧ λ2 ∧ λ3 ∧ wj ∧ (¬λ1∨¬λ2) ∧ (¬λ2∨¬λ3) ∧ (¬λ1∨¬λ3) ∧ (λ1∨¬wj) ∧ (λ2∨¬wj) ∧ (λ3∨¬wj)
H = D 1 ∧ D2 ∧ ∧ Dm (10m clauses)
Transformation is poly-time.

• F satisfiable:
• By theorem, there is setting for the wj such that each Dj has 7 satisfied clauses.
• (H,7m) is in MAX-2-SAT

64
MAX-2-SAT is NP-Complete

Will first show that MAX-2-SAT is in NP.


The witness is a satisfying assignment: for every clause, we check whether the clause is satisfied
and keep track of the number of satisfied clauses. We check whether this number is ≥ m.

Next, we show that 3-SAT ≤ MAX-2-SAT.


F = C1 ∧ C2 ∧ ∧ Cm 3-formula. Will transform it into (H,7m) where H is a 1-2-formula such that
F is satisfiable iff (H,7m) is in MAX-2-SAT, i.e., there is assignment satisfying ≥ 7m clauses of H.

Introduce new variables w1,..., wm.


Cj = λ1 ∨ λ2 ∨ λ3 $
Dj = λ1 ∧ λ2 ∧ λ3 ∧ wj ∧ (¬λ1∨¬λ2) ∧ (¬λ2∨¬λ3) ∧ (¬λ1∨¬λ3) ∧ (λ1∨¬wj) ∧ (λ2∨¬wj) ∧ (λ3∨¬wj)
H = D 1 ∧ D2 ∧ ∧ Dm (10m clauses)
Transformation is poly-time.

• F satisfiable:
• By theorem, there is setting for the wj such that each Dj has 7 satisfied clauses.
• (H,7m) is in MAX-2-SAT

• F not satisfiable:
• By theorem, no matter how wj is chosen, Dj cannot have more than 6 satisfied clauses.
• Hence H cannot have more than 6m satisfied clauses.
• (H,7m) is not in MAX-2-SAT

65
Not-all-equal 3-SAT

An assignment (b1,...,bn) to boolean variables x1,...,xn not-all-equal-satisfies a


clause C = (λ1 ∨ λ2 ∨ ∨ λk) if there is at least one satisfied and one unsatisfied
literal under this assignment.

Example: (1,1,1) does NOT NAE-satisfy (x1 ∨ x2 ∨ x3).

NAE-3-SAT = { F | F is a NAE-satisfiable 3-formula }

66
NAE-3-SAT is NP-Complete

Will first show that NAE-3-SAT is in NP.


The witness is a satisfying assignment: for every clause, check that the assignment NAE-satisfies
the clause. Can be done in polynomial time.

67
NAE-3-SAT is NP-Complete

Will first show that NAE-3-SAT is in NP.


The witness is a satisfying assignment: for every clause, check that the assignment NAE-satisfies
the clause. Can be done in polynomial time.

Next, we show that 3-SAT ≤ NAE-3-SAT.


F = C1 ∧ C2 ∧ ∧ Ck 3-formula. Will transform it into another 3-formula G such that G is NAE-
satisfiable iff F is satisfiable.

68
NAE-3-SAT is NP-Complete

Will first show that NAE-3-SAT is in NP.


The witness is a satisfying assignment: for every clause, check that the assignment NAE-satisfies
the clause. Can be done in polynomial time.

Next, we show that 3-SAT ≤ NAE-3-SAT.


F = C1 ∧ C2 ∧ ∧ Ck 3-formula. Will transform it into another 3-formula G such that G is NAE-
satisfiable iff F is satisfiable.

Introduce new variables z, w1,..., wk.


Cj = λ1 ∨ λ2 ∨ λ3 $ Dj = (λ1 ∨ λ2 ∨ wj) ∧ (¬wj ∨ λ3 ∨ z)
G = D 1 ∧ D2 ∧ ∧ Dk (2k clauses)

69
NAE-3-SAT is NP-Complete

Will first show that NAE-3-SAT is in NP.


The witness is a satisfying assignment: for every clause, check that the assignment NAE-satisfies
the clause. Can be done in polynomial time.

Next, we show that 3-SAT ≤ NAE-3-SAT.


F = C1 ∧ C2 ∧ ∧ Ck 3-formula. Will transform it into another 3-formula G such that G is NAE-
satisfiable iff F is satisfiable.

Introduce new variables z, w1,..., wk.


Cj = λ1 ∨ λ2 ∨ λ3 $ Dj = (λ1 ∨ λ2 ∨ wj) ∧ (¬wj ∨ λ3 ∨ z)
G = D 1 ∧ D2 ∧ ∧ Dk (2k clauses)
Transformation is poly-time.
• F satisfiable:
• if λ1 ∨ λ2 = 1, set wj=0, z=0
G is NAE-satisfiable.
• if λ1 ∨ λ2 = 0, set wj=1, z=0

70
NAE-3-SAT is NP-Complete

Will first show that NAE-3-SAT is in NP.


The witness is a satisfying assignment: for every clause, check that the assignment NAE-satisfies
the clause. Can be done in polynomial time.

Next, we show that 3-SAT ≤ NAE-3-SAT.


F = C1 ∧ C2 ∧ ∧ Ck 3-formula. Will transform it into another 3-formula G such that G is NAE-
satisfiable iff F is satisfiable.

Introduce new variables z, w1,..., wk.


Cj = λ1 ∨ λ2 ∨ λ3 $ Dj = (λ1 ∨ λ2 ∨ wj) ∧ (¬wj ∨ λ3 ∨ z)
G = D 1 ∧ D2 ∧ ∧ Dk (2k clauses)
Transformation is poly-time.
• F satisfiable:
• if λ1 ∨ λ2 = 1, set wj=0, z=0
G is NAE-satisfiable.
• if λ1 ∨ λ2 = 0, set wj=1, z=0

• G NAE-satisfiable:
• (x1,x2,...,xn,w1,...,wk,z=1) NAE-satisfies G iff (¬x1,...,¬xn,¬w1,...,¬wk,z=0) does
• Can assume z = 0 F is satisfiable.
• Then Dj is NAE-satisfiable iff λ1 ∨ λ2 = 1 or λ3 = 1, so iff Cj is satisfiable.

71
Lots more NP-Complete Problems

Richard Karp, 1935 -

In 1972 Richard Karp published a landmark paper entitled

Reducibility among Combinatorial Problems

This paper took the theory of NP-completeness a leap forward by compiling a list of 21 well-
known computational problems which he showed to be NP-complete as well.

We will discuss some of these problems in this class.


72
INDEP-SET is NP-Complete

Reminder:
INDEP-SET = { (G,m) | G is a graph with an independent set of size ≥ m}

We prove that INDEP-SET is NP-complete by showing:


• INDEP-SET is in NP ......................... This one we have already seen

• 3-SAT ≤ INDEP-SET .......................... This one we need to show

To prove 3-SAT ≤ INDEP-SET:


• Take any 3-formula F
• Construct (efficiently) from F a graph G and an integer m such that
F is in 3-SAT % (G,m) is in INDEP-SET

73
INDEP-SET is NP-Complete

F 3-formula with t clauses: F = C1 ∧ C2 ∧ ... ∧ Ct


Construct graph G such that (G,t) is in INDEP-SET iff F is satisfiable.

74
INDEP-SET is NP-Complete

F 3-formula with t clauses: F = C1 ∧ C2 ∧ ... ∧ Ct


Construct graph G such that (G,t) is in INDEP-SET iff F is satisfiable.

Example:

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

x1 ¬x1 ¬x1
For every clause create a triangle with nodes labeled by the literals.
Connect all the nodes of the triangle.

x3 ¬x2 ¬x3 x2 x3
x2

75
INDEP-SET is NP-Complete

F 3-formula with t clauses: F = C1 ∧ C2 ∧ ... ∧ Ct


Construct graph G such that (G,t) is in INDEP-SET iff F is satisfiable.

Example:

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

x1 ¬x1 ¬x1
For every clause create a triangle with nodes labeled by the literals.
Connect all the nodes of the triangle.

x3 ¬x2 ¬x3 x2 x3
Connect literals by an edge who are negations of one another.
x2

76
INDEP-SET is NP-Complete

Suppose that F is satisfiable.


In every clause, pick a literal λ that is satisfied. Mark corresponding node in graph G.
The set of marked nodes forms independent set of size t, so (G,t) is in INDEP-SET.

Example:

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

x1 ¬x1 ¬x1
Pick satisfying assignment (1,0,1):
Pick literal x1 in the first clause, ¬x2 in the second, and x3 in the third.
Corresponding nodes form an independent set. x3 ¬x2 ¬x3 x3
x2
x2

77
INDEP-SET is NP-Complete

Suppose that I is an independent set of G of size ≥ t.


|I| cannot be larger than t: each triangle can contribute at most one node to I and there are t triangles.
Take assignment that satisfies all literals corresponding to nodes in I (exists, since no “contradictions” allowed)
This is a satisfying assignment for F, since every clause has at least one satisfied literal.
Example:

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

x1 ¬x1 ¬x1
Pick independent set given on the right.
This corresponds to the satisfying assignment: x1=0, x2=1, x3=0

x3 ¬x2 ¬x3 x2 x3
x2

78
INDEP-SET is NP-Complete

We already showed that:


• CLIQUE ≤ INDEP-SET ≤ CLIQUE
• NODE-COVER ≤ INDEP-SET ≤ NODE-COVER
So, we obtain
CLIQUE and NODE-COVER are NP-complete as well.

79
Cuts

G=(V,E) graph, w: E $ N positive integer weights on the edges.

A cut in G is a partition of the nodes into two subsets A and B.

The value of the cut is the sum of the edge values of all edges connecting some
node in A to some node in B.

Graph G
Cut of value 7
all edge weights are 1

80
Min-Cut

MIN-CUT = { (G,w, m) | G graph, w edge weights, G has a cut of size ≤ m}

This problem is in P:

(1) set out = inf


(2) For all ordered pair of distinct nodes (s,t) of G do
(a) Run the Ford-Fulkerson algorithm on (G, s,t, w); obtain value c for the min-cut
(b) If c is smaller than out, then replace out by c
(3) Return out

81
Max-Cut

MAX-CUT = { (G,w, m) | G graph, w edge weights, G has a cut of size ≥ m}

This problem cannot be solved the same way (simply multiplying edge weights
with -1 and reducing to MIN-CUT doesn’t work since to solve MIN-CUT the edge
values have to be positive).

What can be said about this problem?

MAX-CUT is NP-complete!

82
Max-Cut is NP-Complete

We prove that MAX-CUT is NP-complete by showing:


• MAX-CUT is in NP ........................................ The witness would be a description of the cut, so easy.

• NAE-3-SAT ≤ MAX-CUT .......................... This one we need to show

To prove NAE-3-SAT ≤ MAX-CUT:


gadget
• Take any 3-formula F
• Construct (efficiently) from F a graph G, weights w, and an integer m such that
F is NAE-satisfiable (G,w) has a cut of size ≥ m

83
The Gadget

F 3-formula with t clauses: F = C1 ∧ C2 ∧ ... ∧ Ct


Construct graph G with weights w such that such that (G,w,5t) is in MAX-CUT iff F is satisfiable.

84
The Gadget

F 3-formula with t clauses: F = C1 ∧ C2 ∧ ... ∧ Ct


Construct graph G with weights w such that such that (G,w,5t) is in MAX-CUT iff F is
satisfiable. Example:

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


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

85
The Gadget

F 3-formula with t clauses: F = C1 ∧ C2 ∧ ... ∧ Ct


Construct graph G with weights w such that such that (G,w,5t) is in MAX-CUT iff F is
satisfiable. Example:

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


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

• Create one node for every variable and its negation


x2 ¬x2

x3 ¬x3

x4 ¬x4

86
The Gadget

F 3-formula with t clauses: F = C1 ∧ C2 ∧ ... ∧ Ct


Construct graph G with weights w such that such that (G,w,5t) is in MAX-CUT iff F is
satisfiable. Example:

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


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

• Create one node for every variable and its negation


x2 ¬x2
• For every clause λ1 ∨ λ2 ∨ λ3 create triangle connecting the
corresponding nodes (if some edge already exists, augment its
weight by 1). x3 ¬x3

x4 ¬x4

87
The Gadget

F 3-formula with t clauses: F = C1 ∧ C2 ∧ ... ∧ Ct


Construct graph G with weights w such that such that (G,w,5t) is in MAX-CUT iff F is
satisfiable. Example:

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


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

• Create one node for every variable and its negation


x2 ¬x2
• For every clause λ1 ∨ λ2 ∨ λ3 create triangle connecting the
corresponding nodes (if some edge already exists, augment its
weight by 1). x3 ¬x3

2
x4 ¬x4

88
The Gadget

F 3-formula with t clauses: F = C1 ∧ C2 ∧ ... ∧ Ct


Construct graph G with weights w such that such that (G,w,5t) is in MAX-CUT iff F is
satisfiable. Example:

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


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

• Create one node for every variable and its negation


x2 ¬x2
• For every clause λ1 ∨ λ2 ∨ λ3 create triangle connecting the
corresponding nodes (if some edge already exists, augment its
weight by 1). x3 ¬x3
2

2
x4 ¬x4

89
The Gadget

F 3-formula with t clauses: F = C1 ∧ C2 ∧ ... ∧ Ct


Construct graph G with weights w such that such that (G,w,5t) is in MAX-CUT iff F is
satisfiable. Example:

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


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

• Create one node for every variable and its negation


x2 ¬x2
• For every clause λ1 ∨ λ2 ∨ λ3 create triangle connecting the 2
corresponding nodes (if some edge already exists, augment its
weight by 1). x3 ¬x3
2

2
x4 ¬x4

90
The Gadget

F 3-formula with t clauses: F = C1 ∧ C2 ∧ ... ∧ Ct


Construct graph G with weights w such that such that (G,w,5t) is in MAX-CUT iff F is
satisfiable. Example:

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


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

• Create one node for every variable and its negation


x2 ¬x2
• For every clause λ1 ∨ λ2 ∨ λ3 create triangle connecting the 2
corresponding nodes (if some edge already exists, augment its
weight by 1). x3 ¬x3
2

2
x4 ¬x4

91
The Gadget

F 3-formula with t clauses: F = C1 ∧ C2 ∧ ... ∧ Ct


Construct graph G with weights w such that such that (G,w,5t) is in MAX-CUT iff F is
satisfiable. Example:

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


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

• Create one node for every variable and its negation


x2 3 ¬x2
• For every clause λ1 ∨ λ2 ∨ λ3 create triangle connecting the 2
corresponding nodes (if some edge already exists, augment its
weight by 1). x3 5 ¬x3
2

2
• Connect the nodes xi and ¬xi by an edge of weight ni, where ni is
x4 5 ¬x4
the number of times xi or its negation appears in the formula.
(NOTE: the sum of all the ni is the total number of literals in the
formula, so 3t) n1=2, n2=3, n3=n4=5

92
The Gadget

F 3-formula with t clauses: F = C1 ∧ C2 ∧ ... ∧ Ct


Construct graph G with weights w such that such that (G,w,5t) is in MAX-CUT iff F is
satisfiable. Example:

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


(x1 ∨ x3 ∨ ¬x4) ∧ (¬x2 ∨ ¬x3 ∨ ¬x4)
• Create one node for every variable and its negation x1 ¬x1
2

• For every clause λ1 ∨ λ2 ∨ λ3 create triangle connecting the


corresponding nodes (if some edge already exists, augment its x2 3 ¬x2
2
weight by 1).

x3 5 ¬x3
• Connect the nodes xi and ¬xi by an edge of weight ni, where ni is 2
the number of times xi or its negation appears in the formula.
2
(NOTE: the sum of all the ni is the total number of literals in the x4 5 ¬x4
formula, i.e., 3t)

• Transformation is polynomial time.

93
The Gadget

Suppose that G has a cut (A,B) of size ≥ 5t:

x1 2 ¬x1

x2 3 ¬x2
2

x3 5 ¬x3
2

2
x4 5 ¬x4

Cut of value 25 = 5t

94
The Gadget

Suppose that G has a cut (A,B) of size ≥ 5t:


(1) We can assume that the variables and their negations belong
to different sides
(a) If literals xi and ¬xi belong to the same side of the cut,
they contribute together at most ni to the cut (each
appearance of one of these literals contributes at most 1 to x1 ¬x1
2
the cut).
(b) Hence, putting them at different sides at most increases
x2 3 ¬x2
the value of the cut. 2
(c) So, if a cut of value ≥ 5t exists, then there is a cut of
value ≥ 5t in which all variables and their negations belong x3 5 ¬x3
2
to different sides of the cut.
2
x4 5 ¬x4

Cut of value 25 = 5t

95
The Gadget

Suppose that G has a cut (A,B) of size ≥ 5t:


(1) We can assume that the variables and their negations belong
to different sides
(2) The variables and their negations contribute ∑i ni = 3t to the
cut. Remaining ≥ 2t has to come from the triangles.
(a) A triangle contributes either 0 or 2 to the cut: 0 if all x1 2 ¬x1
nodes are on the same side of the cut, 2 else.
(b) There are t triangles, so each has to contribute exactly 2 x2 ¬x2
3
to the cut: in each triangle one of the nodes is on one 2
side, the other two on the other side of the cut.
x3 5 ¬x3
2

2
x4 5 ¬x4

Cut of value 25 = 5t

96
The Gadget

Suppose that G has a cut (A,B) of size ≥ 5t:


(1) We can assume that the variables and their negations belong
to different sides
(2) The variables and their negations contribute ∑i ni = 3t to the
cut. Remaining ≥ 2t has to come from the triangles.
(3) Select the assignment which satisfies all the literals in A. x1 2 ¬x1
(a) There is no contradiction (literals and their negations are
on different sides) x2 ¬x2
3
2
(b) Each clause has at least one and at most 2 satisfied
literals (because each triangle contributes exactly 2 to the
x3 5 ¬x3
cut). 2

2
x4 5 ¬x4

Assignment: x1=1, x2=x3=0, x4=1

97
The Gadget

Suppose that G has a cut (A,B) of size ≥ 5t:


(1) We can assume that the variables and their negations belong
to different sides
(2) The variables and their negations contribute ∑i ni = 3t to the
cut. Remaining ≥ 2t has to come from the triangles.
(3) Select the assignment which satisfies all the literals in A. x1 2 ¬x1
(4) F is NAE-satisfiable.
x2 3 ¬x2
2

x3 5 ¬x3
2

2
x4 5 ¬x4

Assignment: x1=1, x2=x3=0, x4=1

98
The Gadget

Suppose that F is NAE-satisfiable. Choose an NAE-satisfying assignment.


(1) Choose as A the set of nodes corresponding to satisfied
literals.
(a) Literals xi and ¬xi belong to different sides of the cut, so
they contribute in total ∑i ni=3t to the cut.
(b) Each triangle contributes 2 to the cut, so in total all x1 2 ¬x1
triangles contribute 2t to the cut.
(2) The value of the corresponding cut is 5t, so (G,w,5t) is in x2 ¬x2
3
MAX-CUT. 2

(x1 ∨ x3 ∨ x4) ∧ (x2 ∨ x3 ∨ x4) ∧ (x2 ∨ ¬x3 ∨ x4) ∧ (x1 ∨ x3 ∨ ¬x4) ∧ (¬x2 ∨ ¬x3 ∨ ¬x4) x3 5 ¬x3
2
has NAE-satisfying assignment x1=x2=1, x3=x4=0.
2
This gives cut of value 25 = 5t. x4 ¬x4
5

99

You might also like