/
February 27, 2019 CS21 Lecture 21 February 27, 2019 CS21 Lecture 21

February 27, 2019 CS21 Lecture 21 - PowerPoint Presentation

natalia-silvester
natalia-silvester . @natalia-silvester
Follow
343 views
Uploaded On 2019-06-29

February 27, 2019 CS21 Lecture 21 - PPT Presentation

1 CS21 Decidability and Tractability Lecture 21 February 27 2019 February 27 2019 CS21 Lecture 21 Outline NPcomplete problems Hamilton path and cycleTraveling Salesperson Problem ID: 760752

cs21 lecture 2019 complete lecture cs21 complete 2019 february path hamilton hampath tsp language subset clause mid graph cycle

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "February 27, 2019 CS21 Lecture 21" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

February 27, 2019

CS21 Lecture 21

1

CS21 Decidability and Tractability

Lecture

21

February 27, 2019

Slide2

February 27, 2019

CS21 Lecture 21

Outline

NP-complete problems: Hamilton path and cycle,Traveling Salesperson ProblemNP-complete problems: Subset SumNP-complete problems: NAE-3-SAT, max cut

2

Slide3

February 27, 2019

CS21 Lecture 21

3

Hamilton Path

Definition: given a directed graph G = (V, E), a

Hamilton path

in G is a directed path that touches every node exactly once.

A language

(decision problem):

HAMPATH = {(G, s, t) : G has a Hamilton path

from s to t

}

Slide4

February 27, 2019

CS21 Lecture 21

4

HAMPATH is NP-complete

Theorem: the following language is NP-complete:HAMPATH = {(G, s, t) : G has a Hamilton path from s to t}Proof:Part 1: HAMPATH NP. Proof?Part 2: HAMPATH is NP-hard.reduce from?

 

Slide5

February 27, 2019

CS21 Lecture 21

5

HAMPATH is NP-complete

We are reducing

from the language

:

3SAT = {

φ

:

φ

is a 3-CNF formula that has a satisfying assignment }

to the language:

HAMPATH = {(G, s, t) : G has a Hamilton path from s to t}

Slide6

February 27, 2019

CS21 Lecture 21

6

HAMPATH is NP-complete

We want to construct a graph from

φ

with the following properties:

a satisfying assignment to

φ

translates into a Hamilton Path from s to t

a Hamilton Path from s to t can be translated into a satisfying assignment for

φ

We will build the graph up from pieces called

gadgets

that “simulate” the clauses and variables of

φ

.

Slide7

February 27, 2019

CS21 Lecture 21

7

HAMPATH is NP-complete

The variable gadget (one for each xi):

x

i

true:

x

i

false:

Slide8

February 27, 2019

CS21 Lecture 21

8

HAMPATH is NP-complete

:

“x

1

“x

2

“x

m

s

t

path from s to t translates into a truth assignment to x

1

…x

m

why must the path be of this form?

Slide9

February 27, 2019

CS21 Lecture 21

9

HAMPATH is NP-complete

φ = (x1x2 x3)(x1 x4 x3) … (…)How to ensure that all k clauses are satisfied?need to add nodes can be visited in path if the clause is satisfiedif visited in path, implies clause is satisfied by the assignment given by path through variable gadgets

 

Slide10

February 27, 2019

CS21 Lecture 21

10

HAMPATH is NP-complete

φ = (x1x2 x3)(x1 x4 x3) … (…)Clause gadget allows “detour” from “assignment path” for each true literal in clause

 

“x

1

“x

2

“x

3

“C

1

Slide11

February 27, 2019

CS21 Lecture 21

11

HAMPATH is NP-complete

One clause gadget for each of k clauses:

“x

1

“x

2

“x

m

:

:

:

“C

1

“C

2

“C

k

:

for clause 1

for clause 2

Slide12

February 27, 2019

CS21 Lecture 21

12

HAMPATH is NP-complete

:

“x

1

“x

2

“x

m

s

t

“C

1

“C

2

“C

k

:

φ

= (x

1

x

2

x

3

)

(

x

1

x

4

x

3

)

 

f(φ) is this graph (edges to/from clause nodes not pictured)

f poly-time computable?

# nodes = O(km)

Slide13

February 27, 2019

CS21 Lecture 21

13

HAMPATH is NP-complete

:

“x

1

“x

2

“x

m

s

t

“C

1

“C

2

“C

k

:

φ

= (x

1

x

2

x

3

)

(

x

1

x

4

x

3

)

 

YES maps to YES?

first form path from satisfying assign.

pick true literal in each clause and add detour

Slide14

February 27, 2019

CS21 Lecture 21

14

HAMPATH is NP-complete

:

“x

1

“x

2

“x

m

s

t

“C

1

“C

2

“C

k

:

φ

= (x

1

x

2

x

3

)

(

x

1

x

4

x

3

)

 

NO maps to NO?

try to translate path into satisfying assignment

if path has “intended” form, OK.

Slide15

February 27, 2019

CS21 Lecture 21

15

HAMPATH is NP-complete

What can go wrong?path has “intended form” unless return from clause gadget to different variable gadget

“x

i

“x

j

“x

h

C

i

we will argue that this cannot happen:

Slide16

February 27, 2019

CS21 Lecture 21

16

HAMPATH is NP-complete

:

Case 1 (positive occurrence of v in clause)

:

c

x

y

z

path must visit y

must enter from x, z, or c

must exit to z (x is taken)

x, c are taken. can’t happen

“v”

Slide17

February 27, 2019

CS21 Lecture 21

17

HAMPATH is NP-complete

:

Case 2 (negative occurrence of v in clause):

c

x

y

path must visit y

must enter from x or z

must exit to z (x is taken)

x is taken. can’t happen

“v”

z

Slide18

February 27, 2019

CS21 Lecture 21

18

Undirected Hamilton Path

HAMPATH refers to a directed graph.

Is it easier on an undirected graph?

A language

(decision problem):

U

HAMPATH = {(G, s, t) :

undirected

G has a Hamilton path from s to t}

Slide19

February 27, 2019

CS21 Lecture 21

19

UHAMPATH is NP-complete

Theorem: the following language is NP-complete:UHAMPATH = {(G, s, t) : undirected graph G has a Hamilton path from s to t}Proof:Part 1: UHAMPATH NP. Proof?Part 2: UHAMPATH is NP-hard.reduce from?

 

Slide20

February 27, 2019

CS21 Lecture 21

20

UHAMPATH is NP-complete

We are reducing

from the language

:

HAMPATH = {(G, s, t) : directed graph G has a Hamilton path from s to t}

to the language:

UHAMPATH = {(G, s, t) : undirected graph G has a Hamilton path from s to t}

Slide21

February 27, 2019

CS21 Lecture 21

21

UHAMPATH is NP-complete

The reduction:

s

t

G

s

out

t

in

G’

u

v

u

in

u

mid

u

out

v

in

v

mid

v

out

replace each node with three (except s, t)

(u

in

, u

mid

)

(u

mid

, u

out

)

(u

out

, v

in

) iff G has (u,v)

Slide22

February 27, 2019

CS21 Lecture 21

22

UHAMPATH is NP-complete

Does the reduction run in poly-time?

YES maps to YES?

Hamilton path in G:

s, u

1

, u

2

, u

3

, …, u

k

, t

Hamilton path in G’:

s

out

, (u

1

)

in

, (u

1

)

mid

, (u

1

)

out

, (u

2

)

in

, (u

2

)

mid

, (u

2

)

out

, … (u

k

)

in

, (u

k

)

mid

, (u

k

)

out

, t

in

Slide23

February 27, 2019

CS21 Lecture 21

23

UHAMPATH is NP-complete

NO maps to NO?

Hamilton path in G’:

s

out

, v

1

, v

2

, v

3

, v

4

, v

5

, v

6

, …, v

k-2

, v

k-1

, v

k

, t

in

v

1

= (u

i1

)

in

for some i

1

(only edges to ins)

v

2

= (u

i1

)

mid

for some i

1

(only way to enter mid)

v

3

= (u

i1

)

out

for some i

1

(only way to exit mid)

v

4

= (u

i2

)

in

for some i

2

(only edges to ins)

...

Hamilton path in G:

s, u

i1

, u

i2

, u

i3

, …, u

ik

, t

Slide24

February 27, 2019

CS21 Lecture 21

24

Undirected Hamilton Cycle

Definition: given a undirected graph G = (V, E), a

Hamilton cycle

in G is a

cycle

in G that touches every node exactly once.

Is finding one easier than finding a Hamilton path?

A language

(decision problem):

U

HAMCYCLE = {G : G has a Hamilton cycle}

Slide25

February 27, 2019

CS21 Lecture 21

25

UHAMCYCLE is NP-complete

Theorem: the following language is NP-complete:UHAMCYCLE = {G: G has a Hamilton cycle}Proof:Part 1: UHAMCYCLE NP. Proof?Part 2: UHAMCYCLE is NP-hard.reduce from?

 

Slide26

February 27, 2019

CS21 Lecture 21

26

UHAMCYCLE is NP-complete

The reduction (from UHAMPATH):

s

t

G

s

t

G’

H. path from s to t implies H. cycle in G’

H. cycle in G’ must visit u via red edges

removing red edges gives H. path from s to t in G

u

Slide27

February 27, 2019

CS21 Lecture 21

27

Traveling Salesperson Problem

Definition: given n cities v1, v2, …, vn and inter-city distances di,j a TSP tour in G is a permutation of {1…n}. The tour’s length is Σi = 1…n d(i),(i+1) (where n+1 means 1).A search problem:given the {di,j}, find the shortest TSP tourcorresponding language (decision problem):TSP = {({di,j : 1 ≤ i<j ≤ n}, k) : these cities have a TSP tour of length ≤ k}

 

Slide28

February 27, 2019

CS21 Lecture 21

28

TSP is NP-complete

Theorem: the following language is NP-complete:TSP = {({di,j : 1 ≤ i<j ≤ n}, k) : these cities have a TSP tour of length ≤ k}Proof:Part 1: TSP NP. Proof?Part 2: TSP is NP-hard.reduce from?

 

Slide29

February 27, 2019

CS21 Lecture 21

29

TSP is NP-complete

We are reducing

from the language

:

UHAMCYCLE = {G : G has a Hamilton cycle}

to the language:

TSP = {({d

i

,

j

: 1 ≤ i<j ≤ n}, k) : these cities have a TSP tour of length

≤ k

}

Slide30

February 27, 2019

CS21 Lecture 21

30

TSP is NP-complete

The reduction:given G = (V, E) with n nodes produce:n cities corresponding to the n nodesdu,v = 1 if (u, v) Edu,v = 2 if (u, v) Eset k = n

 

Slide31

February 27, 2019

CS21 Lecture 21

31

TSP is NP-complete

YES maps to YES?

if G has a Hamilton cycle, then visiting cities in that order gives TSP tour of length n

NO maps to NO?

if TSP tour of length ≤ n, it must have length exactly n.

all distances in tour are 1. Must be edges between every successive pair of cities in tour.

Slide32

February 27, 2019

CS21 Lecture 21

32

Subset Sum

A language

(decision problem):

SUBSET-SUM = {(S = {a

1

, a

2

, a

3

, …, a

k

}, B) : there is a subset of S that sums to B}

example:

S = {1, 7, 28, 3, 2, 5, 9, 32, 41, 11, 8}

B = 30

30 = 7 + 3 + 9 + 11. yes.

Slide33

February 27, 2019

CS21 Lecture 21

33

Subset Sum

SUBSET-SUM = {(S = {a1, a2, a3, …, ak}, B) : there is a subset of S that sums to B}Is this problem NP-complete? in P?Problem set: in TIME(Bpoly(k))

 

Slide34

February 27, 2019

CS21 Lecture 21

34

SUBSET-SUM is NP-complete

Theorem: the following language is NP-complete:SUBSET-SUM = {(S = {a1, a2, a3, …, ak}, B) : there is a subset of S that sums to B}Proof:Part 1: SUBSET-SUM NP. Proof?Part 2: SUBSET-SUM is NP-hard.reduce from?

 

our reduction had better produce super-

polynomially

large B (unless we want to prove P=NP)