CS4102 Algorithms Fall 2018 Warm up: Remember Residual Graphs - - PowerPoint PPT Presentation

cs4102 algorithms
SMART_READER_LITE
LIVE PREVIEW

CS4102 Algorithms Fall 2018 Warm up: Remember Residual Graphs - - PowerPoint PPT Presentation

CS4102 Algorithms Fall 2018 Warm up: Remember Residual Graphs Keep track of net available flow along each edge Forward edges : weight is equal to available flow along that edge in the flow graph =


slide-1
SLIDE 1

CS4102 Algorithms

Fall 2018 Warm up: Remember Residual Graphs

  • Keep track of net available flow along each edge
  • “Forward edges”: weight is equal to available flow along that edge in the

flow graph

– 𝑥 𝑓 = 𝑑 𝑓 − 𝑔(𝑓)

  • “Back edges”: weight is equal to flow along that edge in the flow graph

– 𝑥 𝑓 = 𝑔(𝑓)

1

1/3 1/3 2/3 0/1 𝑡 𝑢 2/2 2/2 1/1 2/3 1/2 1/2 2/3 𝑡 𝑢 2 2 1 3 2 3 1 1 Flow Graph 𝑯 1 2 2 1 2 1 Residual Graph 𝑯𝒈 1

slide-2
SLIDE 2

Today’s Keywords

  • Reductions
  • Bipartite Matching
  • Vertex Cover
  • Independent Set

2

slide-3
SLIDE 3

CLRS Readings

  • Chapter 34

3

slide-4
SLIDE 4

Homeworks

  • HW8 due Friday 11/30 at 11pm

– Written (use LaTeX) – Graphs

4

slide-5
SLIDE 5

Divide and Conquer*

  • Divide:

– Break the problem into multiple subproblems, each smaller instances of the original

  • Conquer:

– If the suproblems are “large”:

  • Solve each subproblem recursively

– If the subproblems are “small”:

  • Solve them directly (base case)
  • Combine:

– Merge together solutions to subproblems

*CLRS Chapter 4

When is this a good strategy?

slide-6
SLIDE 6

Dynamic Programming

  • Requires Optimal Substructure

– Solution to larger problem contains the solutions to smaller ones

  • Idea:
  • 1. Identify recursive structure of the problem
  • 2. Select a good order for solving subproblems
  • Usually smallest problem first

6

slide-7
SLIDE 7

Greedy Algorithms

  • Require Optimal Substructure

– Solution to larger problem contains the solution to a smaller one – Only one subproblem to consider!

  • Idea:
  • 1. Identify a greedy choice property
  • How to make a choice guaranteed to be included in some optimal solution
  • 2. Repeatedly apply the choice property until no subproblems remain

7

slide-8
SLIDE 8

So far

  • Divide and Conquer, Dynamic Programming, Greedy

– Take an instance of Problem A, relate it to smaller instances of Problem A

  • Next:

– Take an instance of Problem A, relate it to an instance of Problem B

8

slide-9
SLIDE 9

Edge-Disjoint Paths

9

Given a graph 𝐻 = (𝑊, 𝐹), a start node 𝑡 and a destination node 𝑢, give the maximum number of paths from 𝑡 to 𝑢 which share no edges

𝑡 𝑢 g h b e f a c Set of edge-disjoint paths of size 3

slide-10
SLIDE 10

Edge-Disjoint Paths

10

Given a graph 𝐻 = (𝑊, 𝐹), a start node 𝑡 and a destination node 𝑢, give the maximum number of paths from 𝑡 to 𝑢 which share no edges

𝑡 𝑢 g h b e f a c Set of edge-disjoint paths of size 4

slide-11
SLIDE 11

Edge-Disjoint Paths Algorithm

11

Make 𝑡 and 𝑢 the source and sink, give each edge capacity 1, find the max flow.

𝑡 𝑢 g h b e f a c Set of edge-disjoint paths of size 4

slide-12
SLIDE 12

Vertex-Disjoint Paths

12

Given a graph 𝐻 = (𝑊, 𝐹), a start node 𝑡 and a destination node 𝑢, give the maximum number of paths from 𝑡 to 𝑢 which share no vertices

𝑡 𝑢 g h b e f a c Not a vertex-disjoint path!

slide-13
SLIDE 13

Vertex-Disjoint Paths Algorithm

13

Idea: Convert an instance of the vertex-disjoint paths problem into an instance of edge-disjoint paths

𝑡 𝑢 g h b e f a c g in

Make two copies of each node, one connected to incoming edges, the other to outgoing edges

g

  • ut

Restricts to 1 edge

Compute Edge-Disjoint paths on new graph

slide-14
SLIDE 14

Maximum Bipartite Matching

14

Dog Lovers Dogs

slide-15
SLIDE 15

Maximum Bipartite Matching

15

Dog Lovers Dogs

slide-16
SLIDE 16

Maximum Bipartite Matching

16

Dog Lovers Dogs

slide-17
SLIDE 17

Maximum Bipartite Matching

Given a graph 𝐻 = (𝑀, 𝑆, 𝐹)

a set of left nodes, right nodes, and edges between left and right

Find the largest set of edges 𝑁 ⊆ 𝐹 such that each node 𝑣 ∈ 𝑀

  • r 𝑤 ∈ 𝑆 is incident to at most one edge.

17

slide-18
SLIDE 18

Make 𝐻 = (𝑀,𝑆, 𝐹) a flow network 𝐻′ = (𝑊′, 𝐹′) by:

  • Adding in a source and sink to the set of nodes:

– 𝑊′ = 𝑀 ∪ 𝑆 ∪ {𝑡, 𝑢}

  • Adding an edge from source to 𝑀 and from 𝑆 to

sink:

– 𝐹′ = 𝐹 ∪ 𝑣 ∈ 𝑀 𝑡, 𝑣 } ∪ 𝑤 ∈ 𝑠 𝑤, 𝑢 }

  • Make each edge capacity 1:

– ∀𝑓 ∈ 𝐹′, 𝑑 𝑓 = 1

Maximum Bipartite Matching Using Max Flow

18

𝑡 𝑢 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1

slide-19
SLIDE 19

Run Time

19

  • 1. Make 𝐻 into 𝐻′
  • 2. Compute Max Flow on 𝐻′
  • 3. Return 𝑁 as all “middle” edges with flow 1

Θ(𝑀 + 𝑆) Θ(𝐹 ⋅ 𝑊) 𝑔 ≤ 𝑀 Θ(𝑀 + 𝑆)

Θ(𝐹 ⋅ 𝑊)

slide-20
SLIDE 20

Reductions

  • Algorithm technique of supreme ultimate power
  • Convert instance of problem A to an instance of Problem B
  • Convert solution of problem B back to a solution of problem A

20

slide-21
SLIDE 21

21

Shows how two different problems relate to each other

Reductions

slide-22
SLIDE 22

MacGyver’s Reduction

22

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-23
SLIDE 23

Bipartite Matching Reduction

23

Bipartite Matching Problem we don’t know how to solve Max Flow Problem we do know how to solve Solution for 𝑪 Solution for 𝑩

3 3 3 2 𝑡 𝑢 1 2 1 3 2 2 3 𝑡 𝑢 2 2 1 3 2 3 1 1 1 2 2 1 2 1 1

Ford Fulkerson

slide-24
SLIDE 24

In General: Reduction

24

Problem we don’t know how to solve Problem we do know how to solve Solution for 𝑪 Solution for 𝑩 Reduction Map Instances of problem 𝑩 to Instances of 𝑪 Using any Algorithm for 𝑪 Map Solutions of problem 𝑪 to Solutions of 𝑩

slide-25
SLIDE 25

Worst-case lower-bound Proofs

reduces to

Algorithm for B

can be used to make

Algorithm for A

The name “reduces” is confusing: it is in the opposite direction of the making 𝑩 is not a harder problem than 𝑪 𝑩 ≤ 𝑪

Opening a door Lighting a fire Alcohol, wood, matches Keg cannon battering ram Problem A Problem B

slide-26
SLIDE 26

Proof of Lower Bound by Reduction

  • 1. We know X is slow

(e.g., X = some way to open the door)

  • 2. Assume Y is quick [toward contradiction]

(Y = some way to light a fire)

  • 3. Show how to use Y to perform X quickly
  • 4. X is slow, but Y could be used to perform X quickly

conclusion: Y must not actually be quick To Show: 𝑍 is slow

slide-27
SLIDE 27

Reduction Proof Notation

27

𝑔(𝑜)-reduces to

Algorithm for B

can be used to make

Algorithm for A

𝑩 is not a harder problem than 𝑪 𝑩 ≤ 𝑪

𝐶 𝑌 𝑍 𝐵

Problem A Problem B

If 𝑩 requires time 𝛁(𝒈 𝒐 ) time then 𝑪 also requires 𝛁(𝒈 𝒐 ) time 𝑩 ≤𝒈(𝒐) 𝑪

With 𝑃(𝑔 𝑜 ) overhead

slide-28
SLIDE 28

Party Problem

28

Draw Edges between people who don’t get along Find the maximum number of people who get along

slide-29
SLIDE 29

Maximum Independent Set

  • Independent set: 𝑇 ⊆ 𝑊 is an independent set if no two nodes

in 𝑇 share an edge

  • Maximum Independent Set Problem: Given a graph 𝐻 = (𝑊, 𝐹)

find the maximum independent set 𝑇

29

slide-30
SLIDE 30

Example

30

Independent set of size 6

slide-31
SLIDE 31

Generalized Baseball

31

slide-32
SLIDE 32

Generalized Baseball

32

Need to place defenders on bases such that every edge is defended What’s the fewest number of defenders needed?

slide-33
SLIDE 33

Minimum Vertex Cover

  • Vertex Cover: 𝐷 ⊆ 𝑊 is a vertex cover if every edge in 𝐹 has
  • ne of its endpoints in 𝐷
  • Minimum Vertex Cover: Given a graph 𝐻 = (𝑊, 𝐹) find the

minimum vertex cover 𝐷

33

slide-34
SLIDE 34

Example

34

Vertex cover of size 5

slide-35
SLIDE 35

MaxIndSet MinVertCov

35

𝑃(𝑊)-reduces to

Algorithm for B

can be used to make

Algorithm for A

𝐶 𝑌 𝑍 𝐵

Problem A Problem B

If 𝑩 requires time 𝛁(𝒈 𝒐 ) time then 𝑪 also requires 𝛁(𝒈 𝒐 ) time 𝑩 ≤𝑾 𝑪

With 𝑃(𝑊) overhead

slide-36
SLIDE 36

We need to build this Reduction

36

Reduction Relate Instances of MaxIndSet to Instances of MinVertCov Using any Algorithm for MinVertCov Relate Solutions of MinVertCov to Solutions of MaxIndSet

O(V) Time

MaxIndSet MinVertCov Solution for MinVertCov Solution for MaxIndSet

slide-37
SLIDE 37

Reduction Idea

37

Independent Set Vertex Cover

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

slide-38
SLIDE 38

Reduction Idea

38

Independent Set Vertex Cover

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

slide-39
SLIDE 39

Proof:

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

39

Let 𝑇 be an independent set Consider any edge 𝑦, 𝑧 ∈ 𝐹 If 𝑦 ∈ 𝑇 then 𝑧 ∉ 𝑇, because o.w. 𝑇 would not be an independent set Therefore 𝑧 ∈ 𝑊 − 𝑇, so edge (𝑦, 𝑧) is covered by 𝑊 − 𝑇

slide-40
SLIDE 40

Proof:

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

40

Let V − 𝑇 be a vertex cover Consider any edge 𝑦, 𝑧 ∈ 𝐹 At least one of 𝑦 and 𝑧 belong to 𝑊 − 𝑇, because V − 𝑇 is a vertex cover

Therefore 𝑦 and 𝑧 are not both in 𝑇, No edge has both end-nodes in 𝑇, thus 𝑇 is an independent set

slide-41
SLIDE 41

MaxVertCov

  • Time Reducable to

MinIndSet

41

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

O(V) Time

slide-42
SLIDE 42

MaxIndSet

  • Time Reducable to

MinVertCov

42

Reduction Do nothing Take complement of solution

O(V) Time

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

slide-43
SLIDE 43

Corollary

43

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-44
SLIDE 44

Corollary

44

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-45
SLIDE 45

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

  • Next time!

45