0% found this document useful (0 votes)
6 views39 pages

05_examples

The document discusses the algorithmic complexity of three problems: 3-SAT, Independent Set, and Clique, demonstrating their NP-completeness. It provides definitions, decision problems, and proofs for each problem, including polynomial-time reductions and verification algorithms. The author concludes that all three problems are NP-complete, highlighting their significance in computational theory.

Uploaded by

chikhimedwassim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views39 pages

05_examples

The document discusses the algorithmic complexity of three problems: 3-SAT, Independent Set, and Clique, demonstrating their NP-completeness. It provides definitions, decision problems, and proofs for each problem, including polynomial-time reductions and verification algorithms. The author concludes that all three problems are NP-complete, highlighting their significance in computational theory.

Uploaded by

chikhimedwassim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Université de Paris

LIPADE

Algorithmic Complexity
Examples of Problems and their Proof of
Complexity

Jean-Guy Mailly ([email protected])

2023
Outline
1

3-SAT

Independent Set

Clique

Conclusion

J.-G. Mailly | Examples


3-SAT
2

Definition
I k -CNF: a CNF formula such that each clause contains at most k
literals
I SAT= {φ | φ is a CNF formula and φ is satisfiable}

J.-G. Mailly | Examples


3-SAT
2

Definition
I k -CNF: a CNF formula such that each clause contains at most k
literals
I SAT= {φ | φ is a CNF formula and φ is satisfiable}
I 3-SAT= {φ | φ is a 3-CNF formula and φ is satisfiable}

J.-G. Mailly | Examples


3-SAT
2

Definition
I k -CNF: a CNF formula such that each clause contains at most k
literals
I SAT= {φ | φ is a CNF formula and φ is satisfiable}
I 3-SAT= {φ | φ is a 3-CNF formula and φ is satisfiable}

We know that SAT is NP-complete. How can we prove that 3-SAT is


also NP-complete?

J.-G. Mailly | Examples


3-SAT is in NP
3

I This part is easy: 3-SAT is a special case of SAT, so it cannot be


harder than the more general version of the problem

J.-G. Mailly | Examples


3-SAT is NP-hard
4

I Intuition: we add new variables that allow to transform one clause


of length > 3 into several clauses of length ≤ 3
I Example: l1 ∨ l2 ∨ · · · ∨ lm , with m > 3, can be replaced by

(l1 ∨ l2 ∨ x) ∧ (l3 ∨ · · · ∨ lm ∨ ¬x) ∧ (l3 ∨ x) ∧ . . . (lm ∨ x)

x a new variable, and l the opposite of a literal, i.e.


with 
¬vi if l is a variable vi
li =
vi if l is the negation of a variable ¬vi
I Repeat the process until there is no more clause of length > 3

J.-G. Mailly | Examples


3-SAT is NP-hard
4

I Intuition: we add new variables that allow to transform one clause


of length > 3 into several clauses of length ≤ 3
I Example: l1 ∨ l2 ∨ · · · ∨ lm , with m > 3, can be replaced by

(l1 ∨ l2 ∨ x) ∧ (l3 ∨ · · · ∨ lm ∨ ¬x) ∧ (l3 ∨ x) ∧ . . . (lm ∨ x)

x a new variable, and l the opposite of a literal, i.e.


with 
¬vi if l is a variable vi
li =
vi if l is the negation of a variable ¬vi
I Repeat the process until there is no more clause of length > 3
I Conclusion: SAT ≤Pf 3 − SAT, so 3-SAT is NP-hard

J.-G. Mailly | Examples


3-SAT is NP-hard
4

I Intuition: we add new variables that allow to transform one clause


of length > 3 into several clauses of length ≤ 3
I Example: l1 ∨ l2 ∨ · · · ∨ lm , with m > 3, can be replaced by

(l1 ∨ l2 ∨ x) ∧ (l3 ∨ · · · ∨ lm ∨ ¬x) ∧ (l3 ∨ x) ∧ . . . (lm ∨ x)

x a new variable, and l the opposite of a literal, i.e.


with 
¬vi if l is a variable vi
li =
vi if l is the negation of a variable ¬vi
I Repeat the process until there is no more clause of length > 3
I Conclusion: SAT ≤Pf 3 − SAT, so 3-SAT is NP-hard
I And so, 3-SAT is NP-complete

J.-G. Mailly | Examples


Outline
5

3-SAT

Independent Set

Clique

Conclusion

J.-G. Mailly | Examples


Independent Set
6

Definition
Given a non directed graph G = hN, Ei, an independent set is a set of
nodes I ⊆ N such that ∀x, y ∈ I, {x, y } 6∈ E

The Decision Problem


IS = {(G, k ) | G has at least one independent set of size ≥ k }

We will prove that IS is NP-complete

J.-G. Mailly | Examples


IS ∈ NP?
7

I To prove that IS ∈ NP, we need to prove that verifying a positive


certificate for IS is ∈ P
I What is a positive certificate for IS?

J.-G. Mailly | Examples


IS ∈ NP?
7

I To prove that IS ∈ NP, we need to prove that verifying a positive


certificate for IS is ∈ P
I What is a positive certificate for IS?
I A positive certificate is an independent set of size ≥ k

J.-G. Mailly | Examples


IS ∈ NP?
7

I To prove that IS ∈ NP, we need to prove that verifying a positive


certificate for IS is ∈ P
I What is a positive certificate for IS?
I A positive certificate is an independent set of size ≥ k
I Exercise: find a polynomial algorithm for verifying if a set of
nodes is an independent set of size ≥ k

J.-G. Mailly | Examples


IS ∈ NP: Proof
8

Algorithm 1 Verifiy IS Certificate


Input: G = hN, Ei, k , I ⊆ N
if |I| < k then
return NO
else
for x ∈ I do
for y ∈ I do
if {x, y } ∈ E then
return NO
end if
end for
end for
return YES
end if

J.-G. Mailly | Examples


IS is NP-hard?
9

I We need to prove that P ≤Pf IS, with P a NP-hard problem


I We use P = 3-SAT
I We have to find f : 3-SAT→ IS such that φ is a satisfiable
3-SAT formula iff f (φ) = (G, k ) with
I G is a non-directed graph
I G has at least one independent set of size ≥ k

J.-G. Mailly | Examples


The Poly-time Reduction for IS (1/4)
10

I We consider a 3-CNF formula φ on variables X = {x1 , . . . , xn }


I φ is a set of clauses {cl1 , . . . , clm }, with each clauses made of (at
most) 3 literals
I For every clause cli we make a "triangle" of nodes: e.g.
φ = (x1 ∨ ¬x2 ∨ x3 ) ∧ (x2 ∨ ¬x3 ∨ x4 )

x1 x2

x¯2 x3 x¯3 x4

I if the same literal appears in several clauses, we duplicate the


node (not the case on this example)

J.-G. Mailly | Examples


The Poly-time Reduction for IS (2/4)
11

I φ = (x1 ∨ ¬x2 ∨ x3 ) ∧ (x2 ∨ ¬x3 ∨ x4 )


I We add an edge between nodes into a same clause

x1 x2

x¯2 x3 x¯3 x4

J.-G. Mailly | Examples


The Poly-time Reduction for IS (2/4)
11

I φ = (x1 ∨ ¬x2 ∨ x3 ) ∧ (x2 ∨ ¬x3 ∨ x4 )


I We add an edge between nodes into a same clause
I We add an edge between pairs of contradictory nodes

x1 x2

x¯2 x3 x¯3 x4

J.-G. Mailly | Examples


The Poly-time Reduction for IS (2/4)
11

I φ = (x1 ∨ ¬x2 ∨ x3 ) ∧ (x2 ∨ ¬x3 ∨ x4 )


I We add an edge between nodes into a same clause
I We add an edge between pairs of contradictory nodes

x1 x2

x¯2 x3 x¯3 x4

I These steps define Gφ ; we choose k = m (number of


clauses/triangles)

J.-G. Mailly | Examples


The Poly-time Reduction for IS (3/4)
12

I Computing is polynomial: at most 3 × m nodes in the graph (m =


number of clauses)
I If φ is satisfiable, let ω be a model of φ. For each clause cli ∈ φ,
we choose a literal li in cli that is satisfied. The set of all li is an IS
of Gφ , with size k . E.g. ω = {x1 , x2 , x3 , x4 } |= φ. Pour cl1 : x1 , pour
cl2 : x2

x1 x2

x¯2 x3 x¯3 x4

J.-G. Mailly | Examples


The Poly-time Reduction for IS (3/4)
12

I Computing is polynomial: at most 3 × m nodes in the graph (m =


number of clauses)
I If φ is satisfiable, let ω be a model of φ. For each clause cli ∈ φ,
we choose a literal li in cli that is satisfied. The set of all li is an IS
of Gφ , with size k . E.g. ω = {x1 , x2 , x3 , x4 } |= φ. Pour cl1 : x1 , pour
cl2 : x2

x1 x2

x¯2 x3 x¯3 x4

J.-G. Mailly | Examples


The Poly-time Reduction for IS (3/4)
12

I Computing is polynomial: at most 3 × m nodes in the graph (m =


number of clauses)
I If φ is satisfiable, let ω be a model of φ. For each clause cli ∈ φ,
we choose a literal li in cli that is satisfied. The set of all li is an IS
of Gφ , with size k . E.g. ω = {x1 , x2 , x3 , x4 } |= φ. Pour cl1 : x1 , pour
cl2 : x2

x1 x2

x¯2 x3 x¯3 x4

I φ ∈ 3-SAT⇒ (Gφ , k ) ∈ IS

J.-G. Mailly | Examples


The Poly-time Reduction for IS (4/4)
13

I Suppose that (Gφ , k ) ∈ IS, let I be an IS of size ≥ k


I For each triangle, there is exactly one node in I
I Nodes xi and x̄i are not together in I (since there is an edge
between them)
I The nodes in I make a satisfying interpretation of φ

J.-G. Mailly | Examples


The Poly-time Reduction for IS (4/4)
13

I Suppose that (Gφ , k ) ∈ IS, let I be an IS of size ≥ k


I For each triangle, there is exactly one node in I
I Nodes xi and x̄i are not together in I (since there is an edge
between them)
I The nodes in I make a satisfying interpretation of φ
I (Gφ , k ) ∈ IS ⇒ φ ∈ 3-SAT

J.-G. Mailly | Examples


The Poly-time Reduction for IS (4/4)
13

I Suppose that (Gφ , k ) ∈ IS, let I be an IS of size ≥ k


I For each triangle, there is exactly one node in I
I Nodes xi and x̄i are not together in I (since there is an edge
between them)
I The nodes in I make a satisfying interpretation of φ
I (Gφ , k ) ∈ IS ⇒ φ ∈ 3-SAT
I 3−SAT≤Pf IS: IS is NP-hard

J.-G. Mailly | Examples


The Poly-time Reduction for IS (4/4)
13

I Suppose that (Gφ , k ) ∈ IS, let I be an IS of size ≥ k


I For each triangle, there is exactly one node in I
I Nodes xi and x̄i are not together in I (since there is an edge
between them)
I The nodes in I make a satisfying interpretation of φ
I (Gφ , k ) ∈ IS ⇒ φ ∈ 3-SAT
I 3−SAT≤Pf IS: IS is NP-hard
I We conclude that IS is NP-complete

J.-G. Mailly | Examples


Outline
14

3-SAT

Independent Set

Clique

Conclusion

J.-G. Mailly | Examples


Clique
15

Definition
Given a non directed graph G = hN, Ei, a clique is a set of nodes
C ⊆ N such that ∀x, y ∈ C, {x, y } ∈ E

Note : this definition of a clique is not exactly the same as the one
given in the first course of the semester, but it is equivalent (and more
convenient for the rest of this lecture)

The Decision Problem


Clique = {(G, k ) | G has at least one clique of size ≥ k }

We will prove that Clique is NP-complete

J.-G. Mailly | Examples


Clique ∈ NP?
16

I To prove that Clique ∈ NP, we need to prove that verifying a


positive certificate for Clique is ∈ P
I What is a positive certificate for Clique?

J.-G. Mailly | Examples


Clique ∈ NP?
16

I To prove that Clique ∈ NP, we need to prove that verifying a


positive certificate for Clique is ∈ P
I What is a positive certificate for Clique?
I A positive certificate is a clique of size ≥ k

J.-G. Mailly | Examples


Clique ∈ NP?
16

I To prove that Clique ∈ NP, we need to prove that verifying a


positive certificate for Clique is ∈ P
I What is a positive certificate for Clique?
I A positive certificate is a clique of size ≥ k
I Exercise: find a polynomial algorithm for verifying if a set of
nodes is a clique of size ≥ k

J.-G. Mailly | Examples


Clique ∈ NP: Proof
17

Algorithm 2 Verifiy Clique Certificate


Input: G = hN, Ei, k , C ⊆ N
if |C| < k then
return NO
else
for x ∈ C do
for y ∈ C do
if {x, y } 6∈ E then
return NO
end if
end for
end for
return YES
end if

J.-G. Mailly | Examples


Clique is NP-hard?
18

I We will prove that IS ≤Pf Clique


I Exercise: prove it

J.-G. Mailly | Examples


Clique is NP-hard: Intuition
19

I From (G = hN, Ei, k ) an instance of IS, make (G0 = hN 0 , E 0 i, k 0 )


an instance of Clique:

J.-G. Mailly | Examples


Clique is NP-hard: Intuition
19

I From (G = hN, Ei, k ) an instance of IS, make (G0 = hN 0 , E 0 i, k 0 )


an instance of Clique:
I k0 = k
I N0 = N
I E 0 = Pairs(N) \ E, where Pairs(N) = {{x, y } | x, y ∈ N}

J.-G. Mailly | Examples


Clique is NP-hard: Intuition
19

I From (G = hN, Ei, k ) an instance of IS, make (G0 = hN 0 , E 0 i, k 0 )


an instance of Clique:
I k0 = k
I N0 = N
I E 0 = Pairs(N) \ E, where Pairs(N) = {{x, y } | x, y ∈ N}
I S ⊆ N is an IS of size k in G iff S is a clique of size k in G0

J.-G. Mailly | Examples


Outline
20

3-SAT

Independent Set

Clique

Conclusion

J.-G. Mailly | Examples


Conclusion
21

I Thanks to Cook’s theorem that SAT is NP-complete, it is possible


to prove the NP-hardness/completeness of other problems
I This is the approach used by Karp to reduce various decision
problems to each other, in different fields (logic, graphs, set
theory, etc)

[Cook 1971] S. A. Cook, The Complexity of Theorem-Proving


Procedures. Proc. of the Third Annual Symposium on Theory of
Computing, 151–158, 1971.
[Karp 1972] R. M. Karp, Reducibility Among Combinatorial
Problems. Proc. of Symposium on the Complexity of Computer
Computations, 85–103, 1972.

J.-G. Mailly | Examples

You might also like