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

Lecture 29 30

The document discusses NP-completeness, focusing on the Cook-Levin theorem which establishes that SAT is NP-complete. It outlines the criteria for proving a problem is NP-complete, including showing it is in NP and that SAT can be polynomially reduced to it. The document also introduces the 3SAT problem and the Independent Sets problem, indicating that both are NP-complete.

Uploaded by

haniasohail777
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)
2 views

Lecture 29 30

The document discusses NP-completeness, focusing on the Cook-Levin theorem which establishes that SAT is NP-complete. It outlines the criteria for proving a problem is NP-complete, including showing it is in NP and that SAT can be polynomially reduced to it. The document also introduces the 3SAT problem and the Independent Sets problem, indicating that both are NP-complete.

Uploaded by

haniasohail777
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/ 50

Theory of Computation

Lecture 29-30

Sarmad Abbasi

Virtual University

December 17, 2007

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 1 / 50


NP-completeness

Last time we finished the proof of the celebrated Cook-Levin theorem


which states that:
Theorem
SAT is NP-complete.

This means
1 SAT is in NP.
2 Every language (problem) in NP is polynomial time reducible to
SAT.
One way to view this theorem is by the following picture:

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 2 / 50


NP-completeness

Last time we finished the proof of the celebrated Cook-Levin theorem


which states that:
Theorem
SAT is NP-complete.

This means
1 SAT is in NP.
2 Every language (problem) in NP is polynomial time reducible to
SAT.
One way to view this theorem is by the following picture:

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 3 / 50


SAT is NP-complete

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 4 / 50


NP-completeness

An immediate question that comes to mind is the following?

Question
Is SAT the only NP-complete problem?

Let us think about this question for a little while.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 5 / 50


NP-completeness

Let us for the sake of argument assume that there is another language
let us call it L that is also NP-complete. What properties it will have:
1 It has to be in NP. Suppose we can establish this by giving a
verification algorithm.
2 All languages L0 ∈ NP will be polynomial time reducible to L.
In particular since SAT ∈ NP hence we must also have

SAT ≤p L.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 6 / 50


NP-completeness

Now suppose that we have a language L such that L is in NP. We


suspect that L is NP-complete. If that is the case then

SAT ≤p L.

Suppose we can establish the fact that

SAT ≤p L. (1)

Then since SAT is itself NP-complete therefore for any language


L0 ∈ NP we have
L0 ≤p SAT (2)

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 7 / 50


NP-completeness

If we combine (1) and (2) we get:

L0 ≤p L
thereby showing that L is NP-complete.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 8 / 50


Hence in order to show that L is NP-complete we only have to do two
things.
1 Give a polynomial time verification algorithm for L. Thereby
showing that L is in NP.
2 Show that SAT ≤p L. Thereby showing indirectly that every
language L0 ∈ NP is polynomial time reducible to L.
Note that showing SAT ≤L is much easier than showing that all
languages L0 ∈ NP reduce to L in polynomial time. Thus we will use
Cook-Levin theorem to establish the NP-completeness of L.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 9 / 50


NP-completeness

For this plan to work we need to recall the following theorem:

Theorem
If A ≤p B and B ≤p C then
A ≤p C
that is ≤p is a transitive relation.

The proof of this fact is so simple that we can revise it in a few minutes.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 10 / 50


NP-completeness

Suppose A ≤p B then there is a function f : Σ∗ → Σ∗ such that


1 x ∈ A if and only if f (x) ∈ B.
2 f can be computed in time O(nk ) for some fixed k .
Similarly since B ≤p C then there is a function g : Σ∗ → Σ∗ such that
1 y ∈ B if and only if g(y ) ∈ C.
2 g can be computed in time O(nl ) for some fixed l.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 11 / 50


NP-completeness

To see that A ≤p C consider the following algorithm:


1 On input x
2 Compute y = f (x)
3 Compute z = g(y ).
4 Output z.
This algorithm computes a function h(x) = g(f (x)) and it is clear that
1 x ∈ A if and only if f (x) ∈ B if and only if g(f (x)) ∈ C. Therefore,
x ∈ A if and only if h(x) ∈ C.
2 Can we compute h in polynomial time?

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 12 / 50


NP-completeness

How much time does it take to compute h. Let |x| = n. Then it takes

O(nk )

time to compute y . and


O(|y |l )
time to compute z.
Thus the total time is
O(nk ) + O(|y |l ).
Now, we realize |y | ≤ O(nk ) therefore, the total time is
 
O(nk ) + O (nk )l = O(nkl )

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 13 / 50


NP-completeness
This theorem gives us the following plan to prove NP-completeness.
Suppose we have a problem K that is known to be NP-complete. Take
SAT for example. Now, we have another problem W that we want to
prove is NP-complete. We can proceed as follows:
1 Show that W is in NP (This is usually easy) by giving a verification
algorithm.
2 Show that K ≤p W . This shows that all languages in NP are
reducible to W .
Note that we must show that

K ≤p W

and not the other way around.


This will be our basic recipe for showing that other problems are
NP-complete. Let us start with one example.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 14 / 50


NP-completeness
Let us start by defining a problem that we will prove is NP-complete.
This problem is going to be very closely related to SAT. We will call it
3SAT . Let us say we have boolean variables x1 , . . . , xn . We call a
variable or it’s negation a literal. Now suppose we have a lot of literals
that are being Or-ed together we will call that a clause. Here are
examples of clauses:

x1 ∨ x5 ∨ x7 .
x1 ∨ x4 ∨ x6 ∨ x8 .
x3 ∨ x5 ∨ x11 .
A formula in conjunctive normal form (CNF) is just an and of clauses.
So it looks like this:

(x1 ∨ x5 ∨ x7 ) ∧ (x1 ∨ x4 ∨ x6 ∨ x8 ) ∧ (x3 ∨ x5 ∨ x11 )

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 15 / 50


NP-completeness

A formula in three (CNF) is just an and of clauses. So that each clause


has three literals. So this formula is not in 3CNF

(x1 ∨ x5 ∨ x7 ) ∧ (x1 ∨ x4 ∨ x6 ∨ x8 ) ∧ (x3 ∨ x5 ∨ x11 )


But this formula is since all clauses have three literals:

(x1 ∨ x5 ∨ x7 ) ∧ (x1 ∨ x4 ∨ x6 ) ∧ (x3 ∨ x5 ∨ x11 )

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 16 / 50


NP-completeness

We will say that a formula is in 3CNF if all the clauses have exactly
three literals.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 17 / 50


NP-completeness

Let us define the following language:

3SAT = {φ : φ is in 3CNF and φ is satisfiable}.


We want to show that 3SAT is NP-complete.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 18 / 50


NP-completeness

1 We have to show that 3SAT is in NP. That is easy and is left as a


homework exercise.
2 We will show that
SAT ≤p 3SAT .

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 19 / 50


NP-completeness

Let φ be a formula. We will show how to construct a formula ψ in 3CNF


such that
1 ψ is in 3CNF.
2 φ is satisfiable if and only if ψ is satisfiable.
3 ψ can be computed from φ in polynomial time.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 20 / 50


NP-completeness

Let us illustrate the proof of this theorem by an example. I will leave the
details to you. Let us say we have a boolean formula φ given by

(((x1 ∨ x3 ) ∧ (x4 ∨ x7 )) ∧ (x2 ∨ x5 )) ∨ x6 .

We will show how to make a formula ψ that is satisfiable if and only if φ


is satisfiable. Firstly we can make a circuit corresponding to this
formula. Here is a circuit.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 21 / 50


3SAT is NP-complete

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 22 / 50


NP-completeness

Now, we can introduce a variable for each wire of the circuit. So, we
first label each wire with y 0 s. As shown in the figure.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 23 / 50


3SAT is NP-complete

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 24 / 50


NP-completeness

Now, let us consider a part of the circuit as shown below:


Here we have two wires y1 and y2 feeding into an or gate and the
output wire is y5 .

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 25 / 50


3SAT is NP-complete

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 26 / 50


NP-completeness

Thus we can write

y5 is true if and only if y1 and y2 are true


We can express this in boolean logic as

y5 ∨ y1 ∨ y2
This says that either y5 is false. Or if it is true then one of the y1 or y2
should be true. Note that this is a clause with three literals.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 27 / 50


NP-completeness

Similarly, suppose we have a and gate with y7 and two wires y3 and y4
feeding into it. We can write

(y7 ∨ y3 ) ∧ (y7 ∨ y4 )

Note these are two clauses with two literals each.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 28 / 50


NP-completeness

So for each wire we can write a formula which is the and over all the
wires. Finally we add the clause yn where yn is the output wire.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 29 / 50


NP-completeness

So for the example we find that the formula looks like

y5 ∧ (y5 ∨ y1 ∨ y2 ) ∧ · · ·

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 30 / 50


NP-completeness

To satisfy this formula the output wire must be set to true. To satisfy
the formula for the output wire the two wires feeding it must be set to
true and so on....Thus to make ψ true we must make an assignment of
the x variables that makes φ true and so on...

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 31 / 50


NP-completeness

This shows the following.


Given φ we can construct ψ such that
1 φ is satisfiable if and only if ψ is satisfiable.
2 ψ is in CNF.
3 Each clause in ψ has at most 3 literals.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 32 / 50


NP-completeness

It is your homework to show that you can now convert ψ into a formula
in which each clause has exactly three literals.
It is easy to see that this transformation can be done in polynomial
time.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 33 / 50


NP-completeness

Theorem
3SAT is NP-complete.

This is our second problem that we have shown to be NP-complete.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 34 / 50


NP-completeness

Now, let us show that a problem from graph theory is NP-complete.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 35 / 50


NP-completeness

Let us start by defining a problem that we will prove is NP-complete.


Let us first recall a definition from graph theory:

Definition
Let G = (V , E) be a graph. I ⊆ V is called an independent set if the
vertices in I have no edges between them. Thus for all x, y ∈ I where
x 6= y
{x, y } 6∈ E.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 36 / 50


NP-completeness

The figure shows a graph on 10 vertices. a, c, d, g is an independent


set.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 37 / 50


NP-completeness

The figure shows a graph on 12 vertices. b, c, f, j,k is an independent


set.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 38 / 50


Independent Sets

Let us define the following language:

IS = {hG, k ii : G has an independent set of size k }.


So computationally we have a problem in which we will be given:
1 A graph G.
2 and an integer k .
We have to find out if G has a independent set of size k .

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 39 / 50


Independent Sets

It is very easy to see that


IS ∈ NP.
We just have to give a verification algorithm. The details are your
homework.
Hint: It is easy to verify that a given set is an independent set in a
graph.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 40 / 50


Independent Sets

We want to show that IS is NP-complete. Now, all we have to do is to


show that
SAT ≤p IS.
Note that this is much easier than the proof of Cook-Levin theorem.
We only have to show that one problem is reducible to IS as opposed
to all the problems in NP. Let’s do that.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 41 / 50


Independent Sets

Theorem
SAT ≤p IS
Consequently IS is also NP-complete.

What do we want to do?


1 We will show that given a formula φ we can construct a graph Gφ
and an integer k such that

φ is satisfiable if and only if Gφ has an independent set of size k

As 3SAT is NP-complete we may assume that φ is in 3CNF.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 42 / 50


Independent Sets

Let us take the formula

(x1 ∨ x2 ∨ x3 ) ∧ (x1 ∨ x3 ∨ x5 ) ∧ (x3 ∨ x2 ∨ x5 )

and make the following graph.


1 For each clause place a cluster of vertices and connect them all to
eachother. Label each vertex with the literal in the clause.
2 Between clauses connect xi and xi .
Let us see how this graph is made.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 43 / 50


Independent Sets

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 44 / 50


Independent Sets

Suppose φ has m clauses and n variables. Then we realize that Gφ will


have m clusters.
First observation is
1 Any independent set must have at most one vertex from a cluster.
2 This means that the largest independent set is of size ≤ m.
Second observation is
1 If xi in one cluster belongs to an independent set then no xi
belongs to the independent set.
2 If xi in one cluster belongs to an independent set then no xi
belongs to the independent set.
Thus we can think of the vertices in the independent set as variables
that are made true in that cluster.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 45 / 50


Independent Sets

This means if there is a independent set that contains m vertices it


must have one vertex from each cluster. Thus the corresponding
assignment must make the formula φ true.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 46 / 50


Independent Sets

On the other hand if we φ is satisfiable then the assignment satisfies


each clause. So, it satisfies one literal in each clause. We can pick all
these literals and get an independent set of size m.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 47 / 50


Independent Sets

Theorem
φ is satisfiable if and only if Gφ contains an independent set of size m.
Where m is the number of clauses in φ.

It is readily seen that Gφ can be computed in polynomial time. So this


shows that
3SAT ≤p IS
Thus IS is NP-complete.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 48 / 50


Independent Sets

Formally the reducibility is given by


1 Input hφi.
2 Let m be the number of clauses in φ.
3 Compute Gφ and output hGφ , mi.

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 49 / 50


Independent Sets

We have so far seen that

SAT ≤p 3SAT ≤ IS
Is it true that
IS ≤p SAT ?

Sarmad Abbasi (Virtual University) Theory of Computation December 17, 2007 50 / 50

You might also like