Other NP-Complete Problems 10.4

Other NP‐Complete Problems
10.4
Mohamed M. El Wakil
[email protected]
1
Agenda
•
•
•
•
•
•
•
Why?
How to describe?
Independent Set Problem
d
d
S
bl
Node Cover Problem
Directed Hamilton Circuit Problem
Undirected Hamilton Circuit Problem
Undirected Hamilton Circuit Problem
Traveling Salesman Problem
2
Remember?
• A problem P is NP
A problem P is NP‐Complete
Complete If:
If:
– P is in NP
• For
For every problem L in NP, there is a polynomial time every problem L in NP there is a polynomial time
reduction from L to P.
• Or, If P1 is NP‐Complete, and there is polynomial time reduction from P1 to P, then P is NP‐Complete.
3
Why?
• When
When a problem is proved to NP
a problem is proved to NP‐Complete
Complete, there is no need to attempt finding an optimal solution for it
solution for it.
• EEvery new NP‐Complete problem, re‐assures NP C
l
bl
that all other NP‐Complete problems require exponential time to solve.
i l i
l
4
NP‐Complete
NP
Complete problems description problems description
•
•
•
•
Name, and abbreviation.
Name
and abbreviation
Input: how it is represented.
O
Output: when the output shall be “Yes”
h
h
h ll b “ ”
The other NP‐Complete problem used to prove the NP‐Completeness of the problem at hand.
5
The Independent Set Problem
The Independent Set Problem
6
Independent Set
Independent Set
• A
A subset I
subset I of the nodes of a graph G is called of the nodes of a graph G is called
an independent set, if no two nodes in I are connected by an edge in G
connected by an edge in G.
– The red
The red nodes are independent sets.
nodes are independent sets
Source: MathWorld
7
The Independent Set Problem (IS)
The Independent Set Problem (IS)
• Given
Given a graph G=(V,E) and integer k (|V|>k>1), a graph G=(V E) and integer k (|V|>k>1)
does G has an independent set of k or more nodes?
• IS is
IS i NP‐Complete, as
NP C
l
1. It is NP.
2. There is polynomial‐time reduction from 3SAT to IS.
8
1. IS is in NP
1. IS is
in NP
• An
An IS guess is verifiable in polynomial time IS guess is verifiable in polynomial time
using DTM:
– Guess a set Gu
Guess a set Gu of k nodes.
of k nodes
– Check that no two nodes make an edge in G.
• Hence, IS is in NP
9
2. 3SAT is reducible to IS in polynomial time
• Input : Input :
– E=(e1)(e2)…(em). – E is 3‐CNF
E is 3 CNF
– i.e. E has 3m literals
• Output:
O t t
– A graph G with 3m nodes, and some edges
– k.
10
Nodes
• Every node is given a name n[i,j]
– i is a clause number (m≥i≥1)
i
l
b ( ≥i≥1)
– j is a literal number (3≥j≥1)
• E=
E
– (x1+x2+x3)
– (~x1+x2+x4)
(~ 1 2 4)
– (~x2+x3+x5)
– (~x3+~x4+~x5)
• A column corresponds to a clause
11
Edges 1/2
Edges 1/2
• Put
Put an edge between all pairs of nodes in a an edge between all pairs of nodes in a
column.
12
Edges 2/2
Edges 2/2
• Put
Put an edge between every complementary an edge between every complementary
pair of nodes.
13
k
• IS
IS’ss k is set to be 3SAT
k is set to be 3SAT’ss m
m
• That is all!
h i ll!
14
Example
15
The Vertex Cover Problem
The Vertex Cover Problem
16
Node/Vertex Cover (NC/VC)
Node/Vertex Cover (NC/VC)
• A
A vertex cover of a graph G=(V,E), is a subset vertex cover of a graph G=(V E) is a subset
of V, such that for every edge in E=(u,v), either u or v is in V
u or v is in V.
• V’={1,3,5,6} is vertex cover
V’ {1 3 5 6} i
• V’’={2,4,5} is another vertex cover
Source: Wikipedia
17
Vertex Cover Problem
Vertex Cover Problem
• Given
Given a graph G=(V,E), and integer k a graph G=(V E) and integer k
(|V|>k>0), does G have a vertex cover with k or fewer nodes?
or fewer nodes?
• VC is NP‐Complete, as
VC i NP C
l
1. It is NP.
2. There is polynomial‐time reduction from IS to VC
18
1. VC is in NP
1. VC is in NP
• A
A VC guess is verifiable in polynomial time VC guess is verifiable in polynomial time
using DTM:
– Guess Gu
Guess Gu a set of k nodes.
a set of k nodes
– Check that each edge in G, has at least one end node in Gu
node in Gu.
• Hence, VC is in NP
19
2. IS is reducible to VC in polynomial time
• VC
VC is the complement of IS!
is the complement of IS!
• If I is largest independent set of graph G=(V,E), then V I is a smallest vertex cover of G
then V‐I, is a smallest vertex cover of G.
– {1,3,5,6} is VCÎ {2,4} is an IS
– {2,4,5} is VC Î
{2 4 5} i VC Î {1,3,6} is an IS
{1 3 6} i
IS
Source: Wikipedia
20
IS reduction to VC
IS reduction to VC
• IS Reduction to VC:
IS Reduction to VC:
– The VC instance G is a copy of the VC instance G.
– The VC instance k is |V|‐k
The VC instance k is |V| kis, where k
where kis is IS
is IS k.
k
• Obviously, this could be done in polynomial time.
21
The Directed Hamilton The Directed Hamilton
Circuit Problem
Circuit Problem
22
A Hamilton Circuit
A Hamilton Circuit
• A
A Hamiltonian circuit is a cycle in a graph Hamiltonian circuit is a cycle in a graph
which visits each vertex exactly once.
• Example:
– Graph: Blue
– HC: Black
Source: Wikipedia
23
Directed Hamilton Circuit Problem (
(DHC)
)
• Given
Given a directed
a directed graph G, does it have a graph G, does it have a
Hamilton circuit?
• DHC is NP‐Complete, as
1. It
1
It is NP.
is NP
2. There is polynomial‐time reduction from 3SAT to DHCP
Source: Wikipedia
24
1. DHC is in NP
1. DHC is in NP
• A
A DHC guess is verifiable in polynomial time DHC guess is verifiable in polynomial time
using DTM:
– Guess Gu
Guess Gu a cycle in G.
a cycle in G
– check if all needed edges are in G.
• Hence, DHC is in NP
H
DHC i i NP
25
2. 3SAT is reducible to DHC in polynomial time
l
l
• This is rather lengthy, so we will skip it!
This is rather lengthy so we will skip it!
26
The Undirected Hamilton The Und
irected Hamilton
Circuit Problem
Circuit Problem
27
Undirected Hamilton Circuit Problem ( )
(HC)
• Given
Given an undirected
an undirected graph G, does G have a graph G does G have a
Hamilton circuit?
• HC is NP‐Complete, as
– HC is in NP
– There is a polynomial time reduction from DHC to HC. 28
HC is in NP
HC is in NP
• A
A HC guess is verifiable in polynomial time HC guess is verifiable in polynomial time
using DTM:
– Guess Gu
Guess Gu a cycle in G.
a cycle in G
– check if all needed edges are in G.
• Hence, DHC is in NP
H
DHC i i NP
29
2. DHC is reducible to HC in polynomial time
• Input:
– Directed graph Gd
• Output
– Undirected graph Gu
30
Constructing Gu ‐ Nodes
Constructing Gu
• For
For every node v in Gd, there are three nodes every node v in Gd there are three nodes
(v0,v1,v2) in Gu
31
Constructing Gu ‐ Edges
Constructing Gu
• Edges:
– For all nodes in Gd, there are two edges in Gu
(v0 v1) and (v1 v2)
(v0,v1), and (v1,v2).
– If there is an edge (vÆw) in Gd, then add edge (v2,w0) to Gu
(v2,w0) to Gu
32
The Traveling Salesman
The Traveling Salesman
Problem
33
Traveling Salesman
A salesman wants to visit all these cities, incurring the least
incurring the least possible cost.
In graph terminology, we want to have a Hamilton circuit with the minimum summation of edges weights.
34
Traveling Salesman Problem (TSP)
Traveling Salesman Problem (TSP)
• Given
Given an undirected weighted graph G, and a an undirected weighted graph G, and a
number k, is there a Hamilton circuit in G, such that the sum of the weights on the edges of the HC is less than or equal k?
•
• TSP is NP‐Complete, as
– TSP is in NP.
– There is a polynomial time reduction from HC to TSP. 35
TSP is in NP
TSP is in NP
• A
A TSP guess is verifiable in polynomial time TSP guess is verifiable in polynomial time
using DTM:
– Guess an itinerary (i.e. cycle) in G
Guess an itinerary (i e cycle) in G
– Check if the sum of the weights of all involved edges is less than or equal k
edges is less than or equal k.
• Hence, TSP is in NP
Hence TSP is in NP
36
2. HC is reducible to TSP in polynomial time
• Input:
– Undirected graph Ghc
• Output
– Undirected weighted graph Gtsp
– Number k
37
Constructing TSP instance
Constructing TSP instance
• Gtsp nodes:
– A copy of Ghc nodes
• Gtsp edges:
d
– A copy of Ghc edges
– Set the weight of all edges to be 1
Set the weight of all edges to be 1
• k
– Set k to be the number of nodes of Ghc
• Evidently, this is polynomial time reduction
38
Conclusion
• Proving NP‐Completeness i
is not easy!
!
– The problem must be proved to be NP
d b NP
– There should be a polynomial time reduction l
i l ti
d ti
from another NP‐Complete problem!
39
That’ss all folks!
That
all folks!
Questions?
40