3-Satisfiability Is NP-complete ∗

Peter Cappello Department of Science University of California, Santa Barbara Santa Barbara, CA 93106 [email protected]

• These notes are not intended to be complete. They are supplemented with figures, and material that arises during the lecture period in response to questions.

∗Based on and Intractability, Michael R. Garey and David S. Johnson, Freeman, 1979.

1 3-Satisfiability, aka 3SAT, is the restricted form of the Satisfiability problem, where each clause has exactly 3 literals.

Theorem: 3-Satisfiability is NP-complete. Proof

• It is easy to check whether or not a given truth assignment satisfies a problem instance’s clauses in polynomial time: 3SAT ∈ NP. • Let

– U = {u1, u2, . . . , un} be a set of variables

– C = {c1, c2, . . . , cm} be a set of clauses making up an arbitrary instance of SAT.

2 • We construct a set C0 of 3-literal clauses on a set U 0 of variables such that C is satisfiable ⇐⇒ C0 is satisfiable. • The construction of C0 replaces each clause in C with a set of “equiv- 0 0 alent” clauses in C , based on U and additional variables Uj used only 0 in clauses Cj. m U 0 = U ∪  U 0   [ j   j=1  and m 0 0 C = [ Cj j=1

• Let an arbitrary clause in C be cj = {, , . . . , zk}. 0 0 • The construction of Cj and Uj depends on k, the number of literals in cj. k = 1:

3 0 1 2 Uj = {yj , yj } 0 1 2 1 2 1 2 1 2 Cj = {{z1, yj , yj }, {z1, yj , yj }, {z1, yj , yj }, {z1, yj , yj }} 0 All of the clauses in Cj are satisfied if and only if z1 evaluates to T . k = 2:

0 1 Uj = {yj } 0 1 1 Cj = {{z1, z2, yj }, {z1, z2, yj }} 0 All of the clauses in Cj are satisfied if and only if z1 or z2 evaluate to T . k = 3:

0 Uj = ∅ 0 Cj = {cj}

4 k > 3:

0 i Uj = {yj, 1 ≤ i ≤ k − 3}

0 1 Cj = {{z1, z2, yj }} i i+1 ∪ {{yj, zi+2, yj }, 1 ≤ i ≤ k − 4} k−3 ∪ {{yj , zk−1, zk}}

For example, if cj = {z1, z2, , , z5, z6, z7} then 0 1 1 2 2 3 3 4 4 Cj = {{z1, z2, yj }, {yj , z3, yj }, {yj , z4, yj }, {yj , z5, yj }, {yj , z6, z7} – 0 If cj is not satisfiable, then Cj is not satisfiable. To see this, eliminate the zis from the clauses. They then cannot all be satisfied. For the example, the reduced set of clauses looks like: 1 1 2 2 3 3 4 4 {{yj }, {yj , yj }, {yj , yj }, {yj , yj }, {yj }.

5 – 0 If cj is satisfiable, then Cj is satisfiable. To see this, let l be the smallest index such that zl evaluates to T . i ∗ If l is 1 or 2, set yj = F . In the example, this looks like

0 Cj = {{z1, z2, F }, {T, z3, F }, {T, z4, F }, {T, z5, F }, {T, z6, z7} i ∗ If l is k − 1 or k, set yj = T . In the example, this looks like

0 Cj = {{z1, z2, T }, {F, z3, T }, {F, z4, T }, {F, z5, T }, {F, z6, z7} ∗ Otherwise, set: i · yj = T for 1 ≤ i ≤ l − 2. i · yj = F for l − 1 ≤ i ≤ k − 3. In the example, if 4 is the smallest index of a literal eval- uating to true, then clauses look like

6 0 Cj = {{z1, z2, T }, {F, z3, T }, {F, z4, F }, {T, z5, F }, {T, z6, z7}

The clauses before zl occurs are satisfiable, because they all i contain a yj that is assigned to T ; The clauses after zl occurs are satisfiable, because they all i i contain a yj, where yj is assigned to F . • Thus, the transformation does the right thing. • The transformation clearly can be constructed in polynomial time, given U and C

7