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

Lecture 26

The lecture discusses NP-completeness, defining NP-complete languages and their significance in relation to the P vs NP problem. It introduces the concept of satisfiability (SAT) and presents the Cook-Levin theorem, which states that SAT is NP-complete. The lecture also outlines a method to reduce the 3-colorability problem to SAT, demonstrating the relationship between these two computational problems.

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 26

The lecture discusses NP-completeness, defining NP-complete languages and their significance in relation to the P vs NP problem. It introduces the concept of satisfiability (SAT) and presents the Cook-Levin theorem, which states that SAT is NP-complete. The lecture also outlines a method to reduce the 3-colorability problem to SAT, demonstrating the relationship between these two computational problems.

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/ 34

Theory of Computation

Lecture 26

Sarmad Abbasi

Sarmad Abbasi () Theory of Computation 1 / 34


NP-completness

Recall that A is NP hard if for all B ∈ NP

B ≤p A.

Let us recall that a language A is called NP-complete if


1 A is NP-hard.
2 A is in NP.

Sarmad Abbasi () Theory of Computation 2 / 34


NP-completness

It is not at all clear that there are NP-complete languages. In fact, if


they exist it would be an amazing fact. These languages will have “all
the complexity” of the class NP. They will be extremely important
because of the following theorem.

Theorem
If A is NP-complete and A is in NP then

P = NP.

Sarmad Abbasi () Theory of Computation 3 / 34


NP-completness

So in order to solve P versus NP problems we will have two


approaches. Suppose we find a NP-complete problem A. A is the
hardest problem in NP. So, either we can
1 try to prove that A is not in P. In fact, NP-complete problems are
the best candidates for this.
2 try to find a polynomial time algorithm for A. If we succeed then
we will show that P = NP.
No one has been able to do any of the above!

Sarmad Abbasi () Theory of Computation 4 / 34


Satisfiability

Let us see what a boolean formula is. Here is an example:

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


A boolean formula is defined as follows. Let us take variable
{x1 , . . . , xn }.
1 0, 1, xi are boolean formulae.
2 If φ and ψ are boolean formulae then so are

φ ∧ ψ, φ ∨ ψ and φ

Sarmad Abbasi () Theory of Computation 5 / 34


Satisfiability
An assignment of τ : {x1 , . . . , xn } → {0, 1}. Each assignment
evaluates a formula to 0 or 1 in the natural way. We substitute the
variable with 0 or 1’s and evaluate the formula by interpreting ∨, ∧ and
¬ as usual.

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


Suppose the assignment is
τ (x1 ) = τ (x2 ) = τ (x4 ) = 0
τ (x3 ) = 1
then the formula becomes
φ = (0 ∨ 1) ∧ (0 ∨ (0 ∧ 0))
Which evaluates to
0
We denote the this by φ|τ .
Sarmad Abbasi () Theory of Computation 6 / 34
Satisfiability

Definition
A formula φ is satisfiable if there exists an assignment τ such that

φ|τ = 1.

Note that if there is a formula with n variables there are potential 2n


assignments. A formula is satisfiable if there is at least one assignment
that makes it 1 (or true).

Sarmad Abbasi () Theory of Computation 7 / 34


Satisfiability

Let us define
SAT = {hφi : φ is satisfiable}.
It is easy to see that
Theorem
SAT is in NP
We can give an easy verification algorithm. The algorithm takes a
formula φ and assignment τ and checks if τ satisfies φ.

Sarmad Abbasi () Theory of Computation 8 / 34


Satisfiability

1 On input hφ, τ i.
2 Substitute the variables using of φ using τ .
3 evaluate the resulting formula with constants.
4 IF the formula evaluates to 1 accept.
This is a verification algorithm for SAT.

Sarmad Abbasi () Theory of Computation 9 / 34


Satisfiability

Theorem (Cook-Levin)
SAT is NP-complete.

Sarmad Abbasi () Theory of Computation 10 / 34


Satisfiability

Theorem (Cook-Levin)
P = NP if and only if SAT ∈ P.

Sarmad Abbasi () Theory of Computation 11 / 34


Satisfiability

The goal of today’s lecture is going to be lead us to the proof of the


Cook-Levin theorem. In order to understand the Cook-Levin theorem
we have to understand what can be expressed in a boolean formula.
We will do this by first reducing one problem in NP to Satisfiability. This
will give us some feel for satisifiablilty and then we can go on to the
proof of the Cook-Levin theorem.

Sarmad Abbasi () Theory of Computation 12 / 34


3-Color

Let G = (V , E) be a graph. We say that G is 3-colorable if we can


assign there colors (say red, blue and green) to its vertices in such a
way that:
1 Each vertex is assigned exactly one color.
2 If {x, y } is an edge then the color of x is different from color of y .

Sarmad Abbasi () Theory of Computation 13 / 34


3-Color
Here is a picture of a graph that is 3-colorable.

Each vertex has been colored and you can check to see if it is a proper
coloring.

Sarmad Abbasi () Theory of Computation 14 / 34


3-Color
Here is a picture of a graph that is not 3-colorable.

It is easy to see that this graph is not three colorable. Since, it has four
vertices all connected to each other therefore we need at least four
colors to color it properly.

Sarmad Abbasi () Theory of Computation 15 / 34


3-Color
Here is a picture of a graph that is not 3-colorable.

It is not easy to see that we cannot properly color it by three colors. You
can exhaustively check at home that this is not a three colorable graph.

Sarmad Abbasi () Theory of Computation 16 / 34


3-Color

Let us now define

3COLOR = {hGi : G is three colorable}.

Sarmad Abbasi () Theory of Computation 17 / 34


3-Color

It is your homework to prove that 3Color is in NP.

Sarmad Abbasi () Theory of Computation 18 / 34


3-Color

We will prove the following theorem today:

Theorem
3Color ≤p SAT .

Lets first try to understand what this means! We do not want to do any
of the following:
1 Design an algorithm to solve SAT.
2 Design an algorithm to solve 3Color .
We want to know the relationship between 3Color and SAT .

Sarmad Abbasi () Theory of Computation 19 / 34


3-Color

What we want is a a polynomial time algorithm A that will take as in


input a graph G and output a Boolean formula φ such that

G is 3 colorable iff φ is satisfiable

Sarmad Abbasi () Theory of Computation 20 / 34


3-Color

What we really want to do is to come up with a Translation Algorithm


that translates the problem of 3-colorability to Satisfiability. In fact given
a graph G we want to be able to come up with a formula φ that is true if
and only if the graph is 3-colorable. For that let us see what the
formula φ will have to “say”

Sarmad Abbasi () Theory of Computation 21 / 34


3-Color

The formula φ will simply say


1 It is possible to assign each vertex exactly one color from red, blue
and green.
2 Furthermore, if two vertices are connected then they get different
colors.

Sarmad Abbasi () Theory of Computation 22 / 34


Satisfiability

Let us look at the following simple formula.

(x1 ∨ x2 )
This formula is true if and only if x1 or x2 is true. Now, let us try to
come up with a formula that is true if exactly one of the variables out of
x1 and x2 is set to true.

Sarmad Abbasi () Theory of Computation 23 / 34


Satisfiability

A little thought shows that the formula is

(x1 ∨ x2 ) ∧ (x1 ∧ x2 )

Now, let us go a bit further. Let us come up with a formula which is true
if and only if exactly one out of the there variables x1 , x2 , x3 is true. A
little thought shows that that formula is

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

Sarmad Abbasi () Theory of Computation 24 / 34


Satisfiability
Now, suppose we have a graph G = (V , E). As an example let us take
the following graph
1 V = {a, b, c, d, e}.
2 E = {{a, b}, {a, c}, {a, d}, {b, d}, {d, e}}
Here is a picture of the graph.

Sarmad Abbasi () Theory of Computation 25 / 34


Satisfiability

Suppose I have three variables for the first vertex a. Let us say they are

Ra , Ba , Ga .

They have the following interpretation:


1 Ra = true means a is colored red.
2 Ba = true means a is colored blue.
3 Ga = true means a is colored green.
How can we come up with a formula that is true if and only if the vertex
a is assigned exactly one color from these three colors?
Easy remember

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

Sarmad Abbasi () Theory of Computation 26 / 34


Satisfiability

So the formula is

(Ra ∨ Ba ∨ Ga ) ∧ (Ra ∧ Ba ) ∧ (Ra ∧ Ga ) ∧ (Ba ∧ Ga )


Similarly

(Rb ∨ Bb ∨ Gb ) ∧ (Rb ∧ Bb ) ∧ (Rb ∧ Gb ) ∧ (Bb ∧ Gb )


is true if and only if b is assigned exactly one color. So it is easy to find
a formula that is true if and only if a given vertex is assigned one out of
there colors.

Sarmad Abbasi () Theory of Computation 27 / 34


Satisfiability

Now, let us consider an edge e = {a, b}. How can we find a formula
that is true if a and b are given different colors. Well that is easy

(Ra ∧ Rb ) ∧ (Ba ∧ Bb ) ∧ (Ga ∧ Gb )

Sarmad Abbasi () Theory of Computation 28 / 34


Satisfiability

So we have learnt two things.


1 Given a vertex v we can make three variables Rv , Bv , Gv and
make a formula that says v is assigned exactly one of the three
colors, red, blue or green.
2 Given an edge {u, w} we can come up with formula that is true (or
says) that u and w must have different colors.
What if we put them together. See what we get:

Sarmad Abbasi () Theory of Computation 29 / 34


Satisfiability

Let G = (V , E) be a graph and Consider the following formula:

!
^ 
φG = (Rv ∨ Bv ∨ Gv ) ∧ Rv ∧ Bv ) ∧ (Rv ∧ Gv ) ∧ (Bv ∧ Gv )
v ∈V
^

 
^  
 (Ra ∧ Rb ) ∧ (Ba ∧ Bb ) ∧ (Ga ∧ Gb ) 
{a,b}∈E

Sarmad Abbasi () Theory of Computation 30 / 34


Satisfiability

This formula “says” that G is three colorable. It is satisfiable true if and


only if we can find a 3Coloring of G.

Sarmad Abbasi () Theory of Computation 31 / 34


Satisfiability

Consider the algorithm:


1 On input G.
2 Compute φG and output it.
This is a polynomial-time reducibility from 3Color to SAT .

Sarmad Abbasi () Theory of Computation 32 / 34


Satisfiability

Note that we have not done the following:


1 Said any thing about how hard is it to solve a SAT.
2 Said anything about how hard it is to solve 3Color.
We have shown that in polynomial time we can reduce 3Color to SAT.

Sarmad Abbasi () Theory of Computation 33 / 34


Satisfiability
Let us look at the little theorem we have proved.
Theorem
3Color ≤p SAT

Let us compare it with the Cook-Levin Theorem.


Theorem
For every language A ∈ NP.

A ≤p SAT .

Thus the Cook-Levin theorem is much more general. It is talking about


an infinite class of problems that is reducible to SAT. To prove that
theorem we need to understand satisfiability, non-deterministic turing
machines and reducibility in a more detail.

Sarmad Abbasi () Theory of Computation 34 / 34

You might also like