Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman...

40
Other NPComplete Problems 10.4 Mohamed M. El Wakil [email protected] [email protected] 1

Transcript of Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman...

Page 1: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

Other NP‐Complete Problems10.4

Mohamed M. El Wakil

[email protected]@elwakil.net

1

Page 2: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

AgendaAgenda

• Why?Why?

• How to describe?

d d S bl• Independent Set Problem

• Node Cover Problem

• Directed Hamilton Circuit Problem

• Undirected Hamilton Circuit ProblemUndirected Hamilton Circuit Problem

• Traveling Salesman Problem

2

Page 3: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

Remember?Remember?

• A problem P is NP‐Complete If:A problem P is NP Complete If:– P is in NP

• For every problem L in NP there is a polynomial timeFor 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

Page 4: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

Why?Why?

• When a problem is proved to NP‐CompleteWhen a problem is proved to NP Complete, there is no need to attempt finding an optimal solution for itsolution for it.

E NP C l bl• Every new NP‐Complete problem, re‐assures that all other NP‐Complete problems require 

i l i lexponential time to solve.

4

Page 5: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

NP‐Complete problems descriptionNP Complete problems description 

• Name and abbreviationName, and abbreviation.

• Input: how it is represented.

O h h h ll b “ ”• Output: when the output shall be “Yes”

• The other NP‐Complete problem used to prove the NP‐Completeness of the problem at hand.

5

Page 6: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

The Independent Set ProblemThe Independent Set Problem

6

Page 7: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

Independent SetIndependent Set

• A subset I of the nodes of a graph G is calledA subset I of the nodes of a graph G is called an independent set, if no two nodes in I are connected by an edge in Gconnected by an edge in G.

The red nodes are independent sets– The red nodes are independent sets.

7

Source: MathWorld

Page 8: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

The Independent Set Problem (IS)The Independent Set Problem (IS)

• Given a graph G=(V E) and integer k (|V|>k>1)Given a graph G=(V,E) and integer k (|V|>k>1), does G has an independent set of k or more nodes?nodes?

IS i NP C l• IS is NP‐Complete, as1. It is NP.

2. There is polynomial‐time reduction from 3SAT to IS.

8

Page 9: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

1. IS is in NP1. IS is in NP

• An IS guess is verifiable in polynomial timeAn IS guess is verifiable in polynomial time using DTM:– Guess a set Gu of k nodes– Guess a set Gu of k nodes.

– Check that no two nodes make an edge in G.

• Hence, IS is in NP

9

Page 10: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

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

O t t• Output:– A graph G with 3m nodes, and some edges

– k.

10

Page 11: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

NodesNodes• Every node is given a name n[i,j]

i i l b ( ≥i≥1)– i is a clause number (m≥i≥1)– j is a literal number (3≥j≥1)

E• E=– (x1+x2+x3)(~ 1 2 4)– (~x1+x2+x4)

– (~x2+x3+x5)(~x3+~x4+~x5)– (~x3+~x4+~x5)

• A column corresponds to a clause11

Page 12: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

Edges 1/2Edges 1/2

• Put an edge between all pairs of nodes in aPut an edge between all pairs of nodes in a column.

12

Page 13: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

Edges 2/2Edges 2/2

• Put an edge between every complementaryPut an edge between every complementary pair of nodes.

13

Page 14: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

kk

• IS’s k is set to be 3SAT’s mIS s k is set to be 3SAT s m

h i ll!• That is all!

14

Page 15: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

ExampleExample

15

Page 16: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

The Vertex Cover ProblemThe Vertex Cover Problem

16

Page 17: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

Node/Vertex Cover (NC/VC)Node/Vertex Cover (NC/VC)

• A vertex cover of a graph G=(V E) is a subsetA 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 Vu or v is in V.

V’ {1 3 5 6} i• V’={1,3,5,6} is vertex cover

• V’’={2,4,5} is another vertex coverSource: Wikipedia

17

Page 18: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

Vertex Cover ProblemVertex Cover Problem

• Given a graph G=(V E) and integer kGiven 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 i NP C l• VC is NP‐Complete, as1. It is NP.

2. There is polynomial‐time reduction from IS to VC

18

Page 19: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

1. VC is in NP1. VC is in NP

• A VC guess is verifiable in polynomial timeA VC guess is verifiable in polynomial time using DTM:– Guess Gu a set of k nodes– Guess Gu a set of k nodes.

– Check that each edge in G, has at least one end node in Gunode in Gu.

• Hence, VC is in NP

19

Page 20: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

2. IS is reducible to VC in polynomial time

• VC is the complement of IS!VC 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 Gthen V‐I, is a smallest vertex cover of G.– {1,3,5,6} is VC {2,4} is an IS

{2 4 5} i VC {1 3 6} i IS– {2,4,5} is VC  {1,3,6} is an IS

Source: Wikipedia

20

Page 21: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

IS reduction to VCIS 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 where k is IS k– The VC instance k is |V|‐kis, where kis is IS k.

• Obviously, this could be done in polynomial time.

21

Page 22: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

The Directed HamiltonThe Directed Hamilton Circuit ProblemCircuit Problem

22

Page 23: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

A Hamilton CircuitA Hamilton Circuit

• A Hamiltonian circuit is a cycle in a graphA Hamiltonian circuit is a cycle in a graph which visits each vertex exactly once.

• Example:– Graph: Blue

– HC: Black

Source: Wikipedia

23

Page 24: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

Directed Hamilton Circuit Problem ( )(DHC)

• Given a directed graph G, does it have aGiven a directed graph G, does it have a Hamilton circuit?

• DHC is NP‐Complete, as1 It is NP1. It is NP.2. There is polynomial‐time reduction from 3SAT to 

DHCPDHCP

24

Source: Wikipedia

Page 25: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

1. DHC is in NP1. DHC is in NP

• A DHC guess is verifiable in polynomial timeA DHC guess is verifiable in polynomial time using DTM:– Guess Gu a cycle in G– Guess Gu a cycle in G.

– check if all needed edges are in G.

H DHC i i NP• Hence, DHC is in NP

25

Page 26: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

2. 3SAT is reducible to DHC in l lpolynomial time

• This is rather lengthy so we will skip it!This is rather lengthy, so we will skip it!

26

Page 27: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

The Undirected HamiltonThe Undirected Hamilton Circuit ProblemCircuit Problem

27

Page 28: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

Undirected Hamilton Circuit Problem ( )(HC)

• Given an undirected graph G does G have aGiven an undirected 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

Page 29: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

HC is in NPHC is in NP

• A HC guess is verifiable in polynomial timeA HC guess is verifiable in polynomial time using DTM:– Guess Gu a cycle in G– Guess Gu a cycle in G.

– check if all needed edges are in G.

H DHC i i NP• Hence, DHC is in NP

29

Page 30: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

2. DHC is reducible to HC in polynomial time

• Input:Input:– Directed graph Gd

• Output– Undirected graph Gu

30

Page 31: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

Constructing Gu ‐ NodesConstructing Gu Nodes

• For every node v in Gd there are three nodesFor every node v in Gd, there are three nodes (v0,v1,v2) in Gu

31

Page 32: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

Constructing Gu ‐ EdgesConstructing Gu Edges

• Edges: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

Page 33: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

The Traveling SalesmanThe Traveling SalesmanProblemProblem

33

Page 34: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

Traveling Salesman

A salesman wants to visit all these cities, incurring the leastincurring the least possible cost.

In graph terminology, we want to have a Hamilton circuit  with the minimum summation of edges weights.

34

Page 35: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

Traveling Salesman Problem (TSP)Traveling Salesman Problem (TSP)

• Given an undirected weighted graph G, and aGiven 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

Page 36: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

TSP is in NPTSP is in NP

• A TSP guess is verifiable in polynomial timeA 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 kedges is less than or equal k.

• Hence TSP is in NP• Hence, TSP is in NP

36

Page 37: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

2. HC is reducible to TSP in polynomial time

• Input:Input:– Undirected graph Ghc

• Output– Undirected weighted graph Gtsp

– Number k

37

Page 38: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

Constructing TSP instanceConstructing TSP instance

• Gtsp nodes:tsp– A copy of Ghc nodes

G d• Gtsp edges:– A copy of Ghc edges– Set the weight of all edges to be 1Set the weight of all edges to be 1

• k– Set k to be the number of nodes of Ghchc

• Evidently, this is polynomial time reduction

38

Page 39: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

Conclusion• Proving NP‐Completeness i !

Conclusion

is not easy!– The problem must be 

d b NPproved to be NP

– There should be a l i l ti d tipolynomial time reduction 

from another NP‐Complete problem!problem!

39

Page 40: Other NP Complete Problems 10 - wmich.eduelise/courses/cs6800/Mohamed... · Traveling Salesman Problem (TSP) • Given an undirected weighted graph G, and a number k, is there a Hamilton

That’s all folks!That s all folks!

Questions?

40