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

lecture23-NP-Complete2

Uploaded by

sezin.laleli
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)
3 views

lecture23-NP-Complete2

Uploaded by

sezin.laleli
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

3SAT and Independent Set

l Recall: To prove a problem Q to be NP-


complete, we pick a known NP-complete
problem P, and show P is polynomial-time
reducible to Q.

l We need at least one known NP-complete


problem to start the ball rolling!
Boolean Satisfiability Theorem
• SAT (Boolean Satisfiability Theorem): Given a
boolean formula, is there some way to assign truth
values (0/1, false/true) to variables of the formula,
such that the formula evaluates to true (1).

– A boolean formula is a logical formula which consists of


variables xi and the logical operators, negation ( x ),
boolean-or (x V y) and boolean-and (x Λ y)
– E.g. F1 = ( x1 Ù ( x2 Ú x3 )) Ù (( x2 Ù x3 ) Ú x1 )
is satisfiable (evaluates to true) if x1=1, x2=0 and x3=0
Cook’s Theorem
l Cook’s Theorem: SAT is NP-complete
- Complicated proof
- Requires background info on Turing machines
- We will not cover
3SAT
• 3SAT: A restricted version of SAT which is the
problem of determining whether a formula in 3-CNF is
satisfiable
• 3-CNF (3-conjunctive normal form): boolean-and of
clauses where each clause is the boolean-or of exactly
3 literals
– A literal is a variable or its negation
– E.g.
F2 = ( x1 Ú x2 Ú x3 ) Ù ( x2 Ú x3 Ú x1 ) Ù ( x1 Ú x4 Ú x3 )
3SAT
l Proof of Cook’s theorem can be modified to
prove that 3SAT is also NP-complete.
Independent Set (IS)
l Now that we know 3SAT is NP-complete, we
can use it to prove other problems are NP-
complete

l Independent Set (IS): Given an undirected


graph G=(V,E) and an integer k, does G contain
a subset S of k vertices such that no two
vertices in S are adjacent to one another.
IS
l IS (shown in blue) of
size 4.
Is IS NP-complete?
l Is IS in NP?
- Certificate consists of k vertices in S
- Verify for each pair of vertices, u,v that there is no
edge between them
- Verifiable in polynomial time
Is IS NP-complete?
l Is IS NP-hard?
l Show that some known NP-complete problem
(3SAT) is reducible to IS in polynomial time.
3SAT

F (G,k) yes
Reduction IS
no

F: boolean formula in 3-CNF


3SAT IS
l What is to be selected?
- 3SAT: which variables are assigned true
- IS: which vertices are to be placed in S

l Requirements:
- 3SAT: Each clause must contain at least one literal whose value is true
- S must contain at least k vertices

l Restrictions:
- 3SAT: If x is assigned true then x must be false and vice versa.
- IS: If u is selected to be in S, then vertices adjacent to u cannot be in S
3SAT IS
l Given F (3-CNF), create G and set k
- Create one vertex in G for each literal that appears in F
l The vertices are grouped into clause clusters.
l Assigning true to a literal from some clause corresponds to
selecting a vertex to place in S
Create one vertex in G for each
literal that appears in F
F3 = ( x1 Ú x2 Ú x3 ) Ù ( x1 Ú x2 Ú x3 ) Ù ( x1 Ú x2 Ú x3 ) Ù ( x1 Ú x2 Ú x3 )

x1 x2 x3

x1 x1

x2 x2

x3 x3

x1 x2 x3
3SAT IS
l Given F (3-CNF), create G and set k
- Create one vertex in G for each literal that appears in F
l The vertices are grouped into clause clusters.
l Assigning true to a literal from some clause corresponds to
selecting a vertex to place in S
- Set k to be the number of clauses
l Forces IS to pick one vertex from each clause—thus one
literal from each clause is true
l connect all vertices in the same clause cluster to each other
to avoid IS selecting two literals from the same clause
connect all vertices in the same
clause cluster to each other
F3 = ( x1 Ú x2 Ú x3 ) Ù ( x1 Ú x2 Ú x3 ) Ù ( x1 Ú x2 Ú x3 ) Ù ( x1 Ú x2 Ú x3 )

x1 x2 x3

x1 x1

x2 x2

x3 x3

x1 x2 x3
3SAT IS
l Given F (3-CNF), create G and set k
- Create one vertex in G for each literal that appears in F
l The vertices are grouped into clause clusters.
l Assigning true to a literal from some clause corresponds to
selecting a vertex to place in S
- Set k to be the number of clauses
l Forces IS to pick one vertex from each clause—thus one
literal from each clause is true
l connect all vertices in the same clause cluster to each other
to avoid IS selecting two literals from the same clause
- Put an edge between each literal and its negation
l To avoid IS placing both in S (to avoid assigning true to
both)
Put an edge between each literal
and its negation
F3 = ( x1 Ú x2 Ú x3 ) Ù ( x1 Ú x2 Ú x3 ) Ù ( x1 Ú x2 Ú x3 ) Ù ( x1 Ú x2 Ú x3 )

x1 x2 x3

x1 x1

x2 x2

x3 x3

x1 x2 x3
Put an edge between each literal
and its negation
F3 = ( x1 Ú x2 Ú x3 ) Ù ( x1 Ú x2 Ú x3 ) Ù ( x1 Ú x2 Ú x3 ) Ù ( x1 Ú x2 Ú x3 )

x1 x2 x3

x1 x1

x2 x2

x3 x3

x1 x2 x3
Put an edge between each literal
and its negation
F3 = ( x1 Ú x2 Ú x3 ) Ù ( x1 Ú x2 Ú x3 ) Ù ( x1 Ú x2 Ú x3 ) Ù ( x1 Ú x2 Ú x3 )

x1 x2 x3

x1 x1 G

x2 x2

x3 x3
k=4

x1 x2 x3
By this construction..
l F is satisfiable if and only if G has an IS of size k
Vertex Cover
Vertex Cover
l A vertex cover in an undirected graph G=(V,E)
is a subset of vertices S such that every edge
in G has at least one endpoint in S

l The Vertex Cover problem (VC) is: given an


undirected graph G and an integer k, does G
have a vertex cover of size k?
Vertex cover
l E.g. useful in many servicing applications.
- For example, you have a computer network and a
program that checks the integrity of the
communication links.
- To save the space, instead of installing the program
on every computer in the network, it suffices to
install it on all the computers forming a vertex
cover.
- From these nodes all the links can be tested
Prove VC NP-complete
l VC is NP
- The certificate consists of the k vertices in the
vertex cover.
- we can easily verify in polynomial time that every
edge is incident to one of k these vertices.
l VC is NP-hard
- Reduction form IS (Independent Set)
S is an IS of size 5
V-S is a Vertex Cover of size 9-5
IS versus VC
• Given an undirected graph G=(V,E) with n
vertices and a subset S ⊆ V of k vertices, the
following are equivalent:
– S is an independent set of size k for G
– V-S is a vertex cover of size n-k for G
Proof
l If S is an independent set for G, then for each
u,v in S, (u,v) is not an edge of G, implying that
every edge in G is incident to a vertex in V-S
implying that V – S is a VC for G.

l If V-S is a VC for G, every edge has at least one


endpoint in V-S implying that for any u,v in S,
there is no edge (u,v) in E.
IS VC
IS (G,k) {
n = number of vertices in G
VC(G, n-k)
}
Dominating Set
l A dominating set in an undirected graph
G=(V,E) is a subset of vertices S such that
every vertex in G is either in S or adjacent to a
vertex in S.
l The Dominating Set (DS) problem is: given an
undirected graph G and an integer k, does G
have a dominating set of size k?
Dominating Set
l useful in facility location problems
- For example, suppose we want to select where to
place a set of fire stations such that every house in
the city is within 2 minutes of the nearest fire
station.
- We create a graph in which two locations are
adjacent if they are within 2 minutes of each other.
- A minimum sized dominating set will be a minimum
set of locations such that every other location is
reachable within 2 minutes from one of these sites
Prove DS is NP-complete
l DS is NP
- The certificate consists of the subset S
l DS is NP-hard
- Reduce Vertex Cover to DS
VC DS
l Find a polynomial time function, which given
an instance of vertex cover (G,k), produces an
instance (G’,k’) such that G has a vertex cover
of size k if and only if G’ has a dominating set
of size k’
VC DS
l Difference:
- VC: every edge is incident to a vertex in S
- DS every vertex is in or adjacent to a vertex in S
l Incidence: property of edges, adjacency:
property of vertices
- Suggests mapping edges of G to vertices of G’ such
that an incident edge is mapped to an adjacent
vertex in G’
If G has a VC of size k then G’ has a VC of size k’

G G’
k=3 k’=3
If G has a VC of size k then G’ has a VC of size k’
Isolated vertex: need not be in VC, has to be in DS

G G’
k=3 k’=3+1

No of isolated vertices
If G’ has a DS of size k’ then G has a VC of size k

DS fog G’ VC for G
If a special vertex is in DS, replace it with one of its
adjacent original vertices

DS fog G’ DS fog G’
If G’ has a DS of size k’ then G has a VC of size k

DS fog G’ VC for G

You might also like