CS4102 Algorithms Fall 2018 Warm up: Grab cookies! Start with 2, - - PowerPoint PPT Presentation

cs4102 algorithms
SMART_READER_LITE
LIVE PREVIEW

CS4102 Algorithms Fall 2018 Warm up: Grab cookies! Start with 2, - - PowerPoint PPT Presentation

CS4102 Algorithms Fall 2018 Warm up: Grab cookies! Start with 2, leftovers will be at regrade office hours Vegan & Gluten-free are available Courtesy of Nate and Robbie Todays Keywords Reductions Bipartite Matching Vertex


slide-1
SLIDE 1

CS4102 Algorithms

Fall 2018 Warm up: Grab cookies! Start with 2, leftovers will be at regrade office hours Vegan & Gluten-free are available Courtesy of Nate and Robbie

slide-2
SLIDE 2

Today’s Keywords

  • Reductions
  • Bipartite Matching
  • Vertex Cover
  • Independent Set
  • NP-Completeness

2

slide-3
SLIDE 3

CLRS Readings

  • Chapter 34

3

slide-4
SLIDE 4

Homeworks

  • HW9 due Friday 12/7 at 11pm

– Written (use LaTeX) – Graphs

4

slide-5
SLIDE 5

𝑙 Independent Set

5

Is there a set of non-adjacent nodes of size 𝑙?

slide-6
SLIDE 6

𝑙 Vertex Cover

6

Is there a set of nodes of size 𝑙 which covers every edge?

slide-7
SLIDE 7

Reduction Idea

7

Independent Set Vertex Cover

𝑇 is an independent set of 𝐻 iff 𝑊 − 𝑇 is a vertex cover of 𝐻

slide-8
SLIDE 8

Reduction Idea

8

Independent Set Vertex Cover

𝑇 is an independent set of 𝐻 iff 𝑊 − 𝑇 is a vertex cover of 𝐻

slide-9
SLIDE 9

MacGyver’s Reduction

9

Opening a door Problem we don’t know how to solve Lighting a fire Problem we do know how to solve Alcohol, wood, matches Solution for 𝑪

𝐵 𝐶

Keg cannon battering ram Solution for 𝑩

Aim duct at door, insert keg

How?

Put fire under the Keg

Reduction

slide-10
SLIDE 10

MaxVertCov 𝑊-Time Reducable to MinIndSet

10

MaxIndSet MinVertCov Solution for MinVertCov

𝐵 𝐶

Solution for MaxIndSet Reduction Do nothing Using any Algorithm for MinVertCov Take complement of solution

𝑍 𝑌

O(V) Time

slide-11
SLIDE 11

Corollary

11

𝐵 𝐶

Reduction Do nothing Using any Algorithm for MinIndSet Take complement of solution

𝑍 𝑌

O(V) Time If Solving 𝑩 was always slow Then this shows solving 𝑪 is also slow

MaxIndSet MinVertCov Solution for MinVertCov Solution for MaxIndSet

slide-12
SLIDE 12

MaxIndSet 𝑊-Time Reducable to MinVertCov

12

𝐵 𝐶

Reduction Do nothing Take complement of solution

𝑍 𝑌

O(V) Time

Using any Algorithm for MaxIndSet MaxIndSet MinVertCov Solution for MinVertCov Solution for MaxIndSet

slide-13
SLIDE 13

Corollary

13

𝐵 𝐶

Reduction Do nothing Take complement of solution

𝑍 𝑌

O(V) Time

Using any Algorithm for MaxVertCov

If Solving 𝑩 was always slow Then this shows solving 𝑪 is also slow

MaxIndSet MinVertCov Solution for MinVertCov Solution for MaxIndSet

slide-14
SLIDE 14

Conclusion

  • MaxIndSet and MinVertCov are either both fast, or both slow

– Spoiler alert: We don’t know which!

  • (But we think they’re both slow)

– Both problems are NP-Complete

14

slide-15
SLIDE 15

Problem Types

  • Decision Problems:

– Is there a solution?

  • Output is True/False

– Is there a vertex cover of size 𝑙?

  • Search Problems:

– Find a solution

  • Output is complex

– Give a vertex cover of size 𝑙

  • Verification Problems:

– Given a potential solution, is it valid?

  • Output is True/False

– Is this a vertex cover of size 𝑙?

15

If we can solve this Then we can solve this

slide-16
SLIDE 16

P vs NP

  • P

– Deterministic Polynomial Time – Problems solvable in polynomial time

  • 𝑃(𝑜𝑞) for some number 𝑞
  • NP

– Non-Deterministic Polynomial Time – Problems verifiable in polynomial time

  • 𝑃(𝑜𝑞) for some number 𝑞
  • Open Problem: Does P=NP?

– Certainly 𝑄 ⊆ 𝑂𝑄

16

P NP

slide-17
SLIDE 17

𝑙-Independent Set is NP

  • To show: Given a potential solution, can we

verify it in 𝑃(𝑜𝑞)? [𝑜 = 𝑊 + 𝐹]

17

How can we verify it?

  • 1. Check that it’s of size 𝑙 𝑃(𝑊)
  • 2. Check that it’s an independent set 𝑃(𝑊2)
slide-18
SLIDE 18

𝑙-Vertex Cover is NP

  • To show: Given a potential solution, can we

verify it in 𝑃(𝑜𝑞)? [𝑜 = 𝑊 + 𝐹]

18

How can we verify it?

  • 1. Check that it’s of size 𝑙 𝑃(𝑊)
  • 2. Check that it’s a Vertex Cover 𝑃(𝐹)
slide-19
SLIDE 19

NP-Hard

  • How can we try to figure out if P=NP?
  • Identify problems at least as “hard” as NP

– If any of these “hard” problems can be solved in polynomial time, then all NP problems can be solved in polynomial time.

  • Definition: NP-Hard:

– 𝐶 is NP-Hard if ∀𝐵 ∈ 𝑂𝑄, 𝐵 ≤𝑞 𝐶 – 𝐵 ≤𝑞 𝐶 means 𝐵 reduces to 𝐶 in polynomial time

19

P NP NP-H

At least as “hard” as NP

slide-20
SLIDE 20

NP-Hardness Reduction

20

Any NP-Hard Problem Problem to show is NP-Hard Solution for 𝑪

𝐵 𝐶

Solution for 𝑩 Reduction

𝑍 𝑌

𝑃(𝑜𝑞) Then this could be done in polynomial time If This could be done in Polynomial time

slide-21
SLIDE 21

NP-Complete

  • “Together they stand, together they fall”
  • Problems solvable in polynomial time iff

ALL NP problems are

  • NP-Complete = NP ∩ NP-Hard
  • How to show a problem is NP-Complete?

– Show it belongs to NP

  • Give a polynomial time verifier

– Show it is NP-Hard

  • Give a reduction from another NP-H problem

21

P NP NP-H NP-C

We now just need a FIRST NP-Hard problem

slide-22
SLIDE 22

NP-Completeness

22

Any NP-Complete Problem Any other NP-Complete Problem Solution for 𝑪

𝐵 𝐶

Solution for 𝑩 Reduction

𝑍 𝑌

𝑃(𝑜𝑞) Then this could be done in polynomial time If This could be done in Polynomial time

slide-23
SLIDE 23

NP-Completeness

23

Any NP-Complete Problem Any other NP-Complete Problem Solution for 𝑪

𝐵 𝐶

Solution for 𝑩 Reduction

𝑍 𝑌

𝑃(𝑜𝑞) Then this cannot be done in polynomial time If this cannot be done in polynomial time

slide-24
SLIDE 24

3-SAT

  • Shown to be NP-Hard by Cook and Levin (independently)
  • Given a 3-CNF formula (logical AND of clauses, each an

OR of 3 variables), Is there an assignment of true/false to each variable to make the formula true?

24

𝑦 ∨ 𝑧 ∨ 𝑨 ∧ 𝑦 ∨ 𝑧 ∨ 𝑧 ∧ 𝑣 ∨ 𝑧 ∨ 𝑨 ∧ 𝑨 ∨ 𝑦 ∨ 𝑣 ∧ (𝑦 ∨ 𝑧 ∨ 𝑨 ) Clause

Variables

𝒚 = 𝒖𝒔𝒗𝒇 𝒛 = 𝒈𝒃𝒎𝒕𝒇 𝒜 = 𝒈𝒃𝒎𝒕𝒇 𝒗 = 𝒖𝒔𝒗𝒇

slide-25
SLIDE 25

𝑙-Independent Set is NP-Complete

  • 1. Show that it belongs to NP

– Give a polynomial time verifier (slide 21)

  • 2. Show it is NP-Hard

– Give a reduction from a known NP-Hard problem – Show 3𝑇𝐵𝑈 ≤𝑞 𝑙𝐽𝑜𝑒𝑇𝑓𝑢

25

slide-26
SLIDE 26

3𝑇𝐵𝑈 ≤𝑞 𝑙𝐽𝑜𝑒𝑇𝑓𝑢

26

3SAT 𝑙-Ind Set Solution for 𝑙-Ind Set

𝐵 𝐶

Solution for 3SAT Reduction

𝑍 𝑌

𝑃(𝑜𝑞)

slide-27
SLIDE 27

Instance of 3SAT to Instance of 𝑙IndSet

27

𝑦 ∨ 𝑧 ∨ 𝑨 ∧ 𝑦 ∨ 𝑧 ∨ 𝑧 ∧ 𝑣 ∨ 𝑧 ∨ 𝑨 ∧ 𝑨 ∨ 𝑦 ∨ 𝑣 ∧ (𝑦 ∨ 𝑧 ∨ 𝑨 )

𝑦 𝑧 𝑨 𝑦 𝑧 𝑧 𝑣 𝑧 𝑨 𝑨 𝑦 𝑣 𝑣 𝑧 𝑨

For each clause, produce a triangle graph with its three variables as nodes

Connect each node to all of its opposites There is a 𝑙-IndSet in this graph, iff there is a satisfying assignment Let 𝑙 = number of clauses

slide-28
SLIDE 28

𝑙IndSet ⇒ Satisfying Assignment

28

𝑦 ∨ 𝑧 ∨ 𝑨 ∧ 𝑦 ∨ 𝑧 ∨ 𝑧 ∧ 𝑣 ∨ 𝑧 ∨ 𝑨 ∧ 𝑨 ∨ 𝑦 ∨ 𝑣 ∧ (𝑦 ∨ 𝑧 ∨ 𝑨 ) One node per triangle is in the Independent set: because we can have exactly 𝑙 total in the set, and 2 in a triangle would be adjacent

𝑦 𝑧 𝑨 𝑦 𝑧 𝑧 𝑣 𝑧 𝑨 𝑨 𝑦 𝑣 𝑣 𝑧 𝑨

If 𝑦 is selected in some triangle, 𝑦 is not selected in any triangle: Because every 𝑦 is adjacent to every 𝑦 Set the variable which each included node represents to “true” 𝒚 = 𝒖𝒔𝒗𝒇 𝒛 = 𝒈𝒃𝒎𝒕𝒇 𝒜 = 𝒈𝒃𝒎𝒕𝒇 𝒗 = 𝒖𝒔𝒗𝒇

slide-29
SLIDE 29

Satisfying Assignment ⇒ 𝑙IndSet

29

𝑦 ∨ 𝑧 ∨ 𝑨 ∧ 𝑦 ∨ 𝑧 ∨ 𝑧 ∧ 𝑣 ∨ 𝑧 ∨ 𝑨 ∧ 𝑨 ∨ 𝑦 ∨ 𝑣 ∧ (𝑦 ∨ 𝑧 ∨ 𝑨 ) Use one true variable from the assignment for each triangle The independent set has 𝑙 nodes, because there are 𝑙 clauses If any variable 𝑦 is true then 𝑦 cannot be true

𝑦 𝑧 𝑨 𝑦 𝑧 𝑧 𝑣 𝑧 𝑨 𝑨 𝑦 𝑣 𝑣 𝑧 𝑨

𝒚 = 𝒖𝒔𝒗𝒇 𝒛 = 𝒈𝒃𝒎𝒕𝒇 𝒜 = 𝒈𝒃𝒎𝒕𝒇 𝒗 = 𝒖𝒔𝒗𝒇

slide-30
SLIDE 30

3𝑇𝐵𝑈 ≤𝑞 𝑙𝐽𝑜𝑒𝑇𝑓𝑢

30

3SAT 𝑙-Ind Set Solution for 𝑙-Ind Set

𝐵 𝐶

Solution for 3SAT Reduction

𝑍 𝑌

𝑃(𝑜𝑞)

Make triangles, connect

  • pposites, 𝑙 = num clauses

Assign true to variables from selected nodes

Then This could be done in polynomial time If This could be done in Polynomial time

slide-31
SLIDE 31

𝑙-Vertex Cover is NP-Complete

  • 1. Show that it belongs to NP

– Give a polynomial time verifier (slide 22)

  • 2. Show it is NP-Hard

– Give a reduction from a known NP-Hard problem – We showed 𝑙𝐽𝑜𝑒𝑇𝑓𝑢 ≤𝑞 𝑙𝑊𝑓𝑠𝑢𝐷𝑝𝑤

  • (Last Class)

31

slide-32
SLIDE 32

𝑙𝐽𝑜𝑒𝑇𝑓𝑢 ≤𝑞 𝑙𝑊𝑓𝑠𝑢𝐷𝑝𝑤

32

𝑙𝐽𝑜𝑒𝑇𝑓𝑢 𝑙𝑊𝑓𝑠𝑢𝐷𝑝𝑤 Solution for 𝑙𝑊𝑓𝑠𝑢𝐷𝑝𝑤

𝐵 𝐶

Solution for 𝑙𝐽𝑜𝑒𝑇𝑓𝑢 Reduction

𝑍 𝑌

𝑃(𝑜𝑞)

𝑙 = 𝑊 − 𝑙 Take Complement of nodes

Then This could be done in polynomial time If This could be done in Polynomial time

slide-33
SLIDE 33

𝑙-Clique Problem

  • Clique: A complete

subgraph

  • 𝑙-Clique Problem:

– Given a graph 𝐻 and a number 𝑙, is there a clique

  • f size 𝑙?

33

3-Clique 4-Clique

slide-34
SLIDE 34

𝑙-Clique is NP-Complete

  • 1. Show that it belongs to NP

– Give a polynomial time verifier

  • 2. Show it is NP-Hard

– Give a reduction from a known NP-Hard problem – We will show 3𝑇𝐵𝑈 ≤𝑞 𝑙𝐷𝑚𝑗𝑟𝑣𝑓

34

slide-35
SLIDE 35

𝑙-Clique is NP

  • 1. Given a Graph and a potential solution
  • 2. Check that the solution has 𝑙 nodes
  • 3. Check that every pair of nodes share an edge

35

3-Clique 4-Clique

slide-36
SLIDE 36

3𝑇𝐵𝑈 ≤𝑞 𝑙𝐷𝑚𝑗𝑟𝑣𝑓

36

3𝑇𝐵𝑈 𝑙𝐷𝑚𝑗𝑟𝑣𝑓 Solution for𝑙𝐷𝑚𝑗𝑟𝑣𝑓

𝐵 𝐶

Solution for 3𝑇𝐵𝑈 Reduction

𝑍 𝑌

𝑃(𝑜𝑞)

slide-37
SLIDE 37

Instance of 3SAT to Instance of 𝑙Clique

37

𝑦 𝑧 𝑨 𝑦 𝑧 𝑧 𝑣 𝑧 𝑨

For each clause, produce a node for each of its three variables Connect each node to all non-contradictory nodes in the other clauses (i.e., anything that’s not its negation)

(also do this for the other clauses, omitted due to clutter)

There is a 𝑙-Clique in this graph, iff there is a satisfying assignment Let 𝑙 = number of clauses

𝑦 ∨ 𝑧 ∨ 𝑨 ∧ 𝑦 ∨ 𝑧 ∨ 𝑧 ∧ 𝑣 ∨ 𝑧 ∨ 𝑨 ∧ 𝑨 ∨ 𝑦 ∨ 𝑣 ∧ (𝑦 ∨ 𝑧 ∨ 𝑨 )

𝑨 𝑦 𝑣 𝑣 𝑧 𝑨

slide-38
SLIDE 38

𝑙Clique ⇒ Satisfying Assignment

38

𝑦 ∨ 𝑧 ∨ 𝑨 ∧ 𝑦 ∨ 𝑧 ∨ 𝑧 ∧ 𝑣 ∨ 𝑧 ∨ 𝑨 ∧ 𝑨 ∨ 𝑦 ∨ 𝑣 ∧ (𝑦 ∨ 𝑧 ∨ 𝑨 ) There are 𝑙 triplets in the graph, and no two nodes in the same triplet are adjacent 𝒚 = 𝒖𝒔𝒗𝒇 𝒛 = 𝒈𝒃𝒎𝒕𝒇 𝒜 = 𝒈𝒃𝒎𝒕𝒇 𝒗 = 𝒖𝒔𝒗𝒇

𝑦 𝑧 𝑨 𝑦 𝑧 𝑧 𝑣 𝑧 𝑨 𝑨 𝑦 𝑣 𝑣 𝑧 𝑨

To have a 𝑙-Clique, must have one node from each triplet Cannot select a node for both a variable and its negation Therefore selection of nodes is a satisfying assignment

slide-39
SLIDE 39

Satisfying Assignment⇒ 𝑙Clique

39

𝑦 ∨ 𝑧 ∨ 𝑨 ∧ 𝑦 ∨ 𝑧 ∨ 𝑧 ∧ 𝑣 ∨ 𝑧 ∨ 𝑨 ∧ 𝑨 ∨ 𝑦 ∨ 𝑣 ∧ (𝑦 ∨ 𝑧 ∨ 𝑨 ) Select one node for a true variable from each clause 𝒚 = 𝒖𝒔𝒗𝒇 𝒛 = 𝒈𝒃𝒎𝒕𝒇 𝒜 = 𝒈𝒃𝒎𝒕𝒇 𝒗 = 𝒖𝒔𝒗𝒇

𝑦 𝑧 𝑨 𝑦 𝑧 𝑧 𝑣 𝑧 𝑨 𝑨 𝑦 𝑣 𝑣 𝑧 𝑨

There will be 𝑙 nodes selected We can’t select both a node and its negation All nodes will be non-contradictory, so they will be pairwise adjacent

slide-40
SLIDE 40

3𝑇𝐵𝑈 ≤𝑞 𝑙𝐷𝑚𝑗𝑟𝑣𝑓

40

3𝑇𝐵𝑈

𝐵 𝐶

Solution for 3𝑇𝐵𝑈 Reduction

𝑍 𝑌

𝑃(𝑜𝑞)

Make a triplet per clause, connect non-contraditcory nodes among clauses Assign each variable selected to True 𝑙𝐷𝑚𝑗𝑟𝑣𝑓 Solution for𝑙𝐷𝑚𝑗𝑟𝑣𝑓

Then This could be done in polynomial time If This could be done in Polynomial time

slide-41
SLIDE 41

Reduction

41

𝑙-VertexCover Solver 𝑙-VertexCover Decider Solution for 𝑪

𝐵 𝐶

Solution for 𝑩 Reduction Remove a node, etc… Using any Algorithm for 𝑪 Relate Solutions of problem 𝑪 to Solutions of 𝑩

𝑍 𝑌

slide-42
SLIDE 42

Problem Types

  • Decision Problems:

– Is there a solution?

  • Output is True/False

– Is there a vertex cover of size 𝑙?

  • Search Problems:

– Find a solution

  • Output is complex

– Give a vertex cover of size 𝑙

  • Verification Problems:

– Given a potential solution, is it valid?

  • Output is True/False

– Is this a vertex cover of size 𝑙?

42

If we can solve this Then we can solve this

slide-43
SLIDE 43

Using a 𝑙-VertexCover decider to build a searcher

  • Set 𝑗 = 𝑙 − 1
  • Remove nodes (and incident edges) one at a time
  • Check if there is a vertex cover of size 𝑗

– If so, then that removed node was part of the 𝑙 vertex cover, set 𝑗 = 𝑗 − 1 – Else, it wasn’t

43

slide-44
SLIDE 44

5 Vertex Cover (Decision)

44

Is there a set of nodes of size 5 which covers every edge? Yes!

slide-45
SLIDE 45

4 Vertex Cover (Decision)

45

Is there a set of nodes of size 4 which covers every edge? No!

slide-46
SLIDE 46

4 Vertex Cover (Decision)

46

Is there a set of nodes of size 4 which covers every edge? Yes!

slide-47
SLIDE 47

3 Vertex Cover (Decision)

47

Is there a set of nodes of size 3 which covers every edge? No!