36
2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers 12 1 School of Computer Science and Engineering, UNSW Australia 2 Optimisation Resarch Group, NICTA Semester 2, 2015 S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 1 / 30

2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

  • Upload
    others

  • View
    15

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

2. Dynamic Programming

COMP6741: Parameterized and Exact Computation

Serge Gaspers12

1School of Computer Science and Engineering, UNSW Australia2Optimisation Resarch Group, NICTA

Semester 2, 2015

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 1 / 30

Page 2: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Outline

1 Dynamic Programming Across SubsetsTraveling Salesman ProblemColoringDominating Set in bipartite graphs

2 Further Reading

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 2 / 30

Page 3: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Outline

1 Dynamic Programming Across SubsetsTraveling Salesman ProblemColoringDominating Set in bipartite graphs

2 Further Reading

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 3 / 30

Page 4: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Dynamic Programming across Subsets

very general technique

uses solutions of subproblems

typically stored in a table of exponential size

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 4 / 30

Page 5: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Outline

1 Dynamic Programming Across SubsetsTraveling Salesman ProblemColoringDominating Set in bipartite graphs

2 Further Reading

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 5 / 30

Page 6: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Traveling Salesman Problem

Traveling Salesman Problem (TSP)

Input: a set of n cities, the distance d(i, j) ∈ N between every two citiesi and j, integer k

Question: Is there a permutation of the cities (a tour) such that the totaldistance when traveling from city to city in the specified order, andreturning back to the origin, is at most k?

17

13

12

7

14

3

45

4

3

Brute-force: Try all permutations of cities; O∗(n!)S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 6 / 30

Page 7: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Dynamic Programming for TSP I

For a non-empty subset of cities S ⊆ {2, 3, ..., n} and city i ∈ S:

Opt[S; i] ≡ length of the shortest path starting in city 1, visits all cities inS \ {i} and ends in i.

Then,

Opt[{i}; i] = d(1, i)

Opt[S; i] = min{Opt[S \ {i}; j] + d(j, i) : j ∈ S \ {i}}

For each subset S in order of increasing cardinality, compute Opt[S; i] foreach i.

Final solution:

min2≤j≤n

{Opt[{2, 3, ..., n}; j] + d(j, 1)}

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 7 / 30

Page 8: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Dynamic Programming for TSP II

Theorem 1 (Held & Karp ’62)

TSP can be solved in time O(2nn2) = O∗(2n).

best known algo for TSP

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 8 / 30

Page 9: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 9 / 30

Page 10: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Outline

1 Dynamic Programming Across SubsetsTraveling Salesman ProblemColoringDominating Set in bipartite graphs

2 Further Reading

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 10 / 30

Page 11: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Coloring

A k-coloring of a graph G = (V,E) is a function f : V → {1, 2, ..., k} assigningcolors to V such that no two adjacent vertices receive the same color.

ColoringInput: Graph G, integer kQuestion: Does G have a k-coloring?

a b

c d e

f g h

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 11 / 30

Page 12: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Exercise

A k-coloring of a graph G = (V,E) is a function f : V → {1, 2, ..., k} assigningcolors to V such that no two adjacent vertices receive the same color.

ColoringInput: Graph G, integer kQuestion: Does G have a k-coloring?

Exercise

Design an O∗(4n) time algorithm for Coloring.

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 12 / 30

Page 13: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Maximal Independent Sets

An independent set is maximal if it is not a subset of any other independentset.

Examples:

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 13 / 30

Page 14: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Coloring and Maximal Independent Sets

Theorem 2 ([Moon, Moser ’65], [Johnson, Yannakakis, Papadimitriou ’88])

A graph on n vertices contains at most 3n/3 ⊆ O(1.4423n) maximal independentsets. Moreover, they can all be enumerated in time O∗(3n/3).

Lemma 3 ([Lawler ’76])

For any graph G, there exists an optimal coloring for G where one color class is amaximal independent set in G.

Proof.Exercise

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 14 / 30

Page 15: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Coloring and Maximal Independent Sets

Theorem 2 ([Moon, Moser ’65], [Johnson, Yannakakis, Papadimitriou ’88])

A graph on n vertices contains at most 3n/3 ⊆ O(1.4423n) maximal independentsets. Moreover, they can all be enumerated in time O∗(3n/3).

Lemma 3 ([Lawler ’76])

For any graph G, there exists an optimal coloring for G where one color class is amaximal independent set in G.

Proof.Exercise

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 14 / 30

Page 16: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Dynamic Programming for Coloring I

G[S] ≡ subgraph of G induced by the vertices in S

Opt[S] ≡ minimum k such that G[S] is k-colorable.

Then,

Opt[∅] = 0

Opt[S] = 1 + min{Opt[S \ I] : I maximal ind. set in G[S]}

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 15 / 30

Page 17: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Dynamic Programming for Coloring II

Opt[∅] = 0

Opt[S] = 1 + min{Opt[S \ I] : I maximal ind. set in G[S]}

go through the sets S in order of increasing cardinality

to compute Opt[S], generate all maximal independent sets I of G[S]

this can be done in time |S|23|S|/3

time complexity:

n∑s=0

(n

s

)s23s/3 ≤ n2

n∑s=0

(n

s

)3s/3 = n2(1 + 31/3)n = O(2.4423n)

[Recall the Binomial Theorem: (x+ y)n =∑n

k=0

(nk

)xn−kyk.]

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 16 / 30

Page 18: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Dynamic Programming for Coloring III

Theorem 4 ([Lawler ’76])

Coloring can be solved in time O(2.4423n).

was best known algorithm for 25 years (until [Eppstein ’01])

current best: O∗(2n) [Bjørklund & Husfeldt ’06], [Koivisto ’06]

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 17 / 30

Page 19: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

k-Coloring for small k

k-ColoringInput: Graph G, integer kQuestion: Does G have a k-coloring?

k ≤ 2: polynomial

k > 2: NP-complete

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 18 / 30

Page 20: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Algorithm for 3-Coloring

Theorem 5 ([Lawler ’76])

3-Coloring can be decided in time O(1.4423n).

Proof.For every maximal independent I set of G, check if G− I is 2-colorable.

current best: O(1.3289n) [Eppstein ’01]

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 19 / 30

Page 21: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Algorithm for 3-Coloring

Theorem 5 ([Lawler ’76])

3-Coloring can be decided in time O(1.4423n).

Proof.For every maximal independent I set of G, check if G− I is 2-colorable.

current best: O(1.3289n) [Eppstein ’01]

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 19 / 30

Page 22: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Algorithm for 3-Coloring

Theorem 5 ([Lawler ’76])

3-Coloring can be decided in time O(1.4423n).

Proof.For every maximal independent I set of G, check if G− I is 2-colorable.

current best: O(1.3289n) [Eppstein ’01]

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 19 / 30

Page 23: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Algorithm for 4-Coloring

Theorem 6

4-Coloring can be decided in time O(1.7851n).

Proof.

For each maximal independent set I of G of size at least n/4, check if G− Iis 3-colorable.

We need to prove that each 4-colorable graph G has a 4-coloring where onecolor class is a maximal i.s. of size ≥ n/4?

Pick a 4-coloring of G.

≥ 1 color class contains ≥ n/4 vertices.

If this color class is not a maximal i.s., recolor some other vertices such thatit becomes a maximal i.s.

Running time: O(3n/31.32893n/4) ⊆ O(1.7851n)

current best: O(1.7272n) [Fomin, Gaspers, Saurabh ’07]

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 20 / 30

Page 24: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Algorithm for 4-Coloring

Theorem 6

4-Coloring can be decided in time O(1.7851n).

Proof.

For each maximal independent set I of G of size at least n/4, check if G− Iis 3-colorable.

We need to prove that each 4-colorable graph G has a 4-coloring where onecolor class is a maximal i.s. of size ≥ n/4?

Pick a 4-coloring of G.

≥ 1 color class contains ≥ n/4 vertices.

If this color class is not a maximal i.s., recolor some other vertices such thatit becomes a maximal i.s.

Running time: O(3n/31.32893n/4) ⊆ O(1.7851n)

current best: O(1.7272n) [Fomin, Gaspers, Saurabh ’07]

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 20 / 30

Page 25: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Algorithm for 4-Coloring

Theorem 6

4-Coloring can be decided in time O(1.7851n).

Proof.

For each maximal independent set I of G of size at least n/4, check if G− Iis 3-colorable.

We need to prove that each 4-colorable graph G has a 4-coloring where onecolor class is a maximal i.s. of size ≥ n/4?

Pick a 4-coloring of G.

≥ 1 color class contains ≥ n/4 vertices.

If this color class is not a maximal i.s., recolor some other vertices such thatit becomes a maximal i.s.

Running time: O(3n/31.32893n/4) ⊆ O(1.7851n)

current best: O(1.7272n) [Fomin, Gaspers, Saurabh ’07]

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 20 / 30

Page 26: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Algorithm for 4-Coloring

Theorem 6

4-Coloring can be decided in time O(1.7851n).

Proof.

For each maximal independent set I of G of size at least n/4, check if G− Iis 3-colorable.

We need to prove that each 4-colorable graph G has a 4-coloring where onecolor class is a maximal i.s. of size ≥ n/4?

Pick a 4-coloring of G.

≥ 1 color class contains ≥ n/4 vertices.

If this color class is not a maximal i.s., recolor some other vertices such thatit becomes a maximal i.s.

Running time: O(3n/31.32893n/4) ⊆ O(1.7851n)

current best: O(1.7272n) [Fomin, Gaspers, Saurabh ’07]

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 20 / 30

Page 27: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Outline

1 Dynamic Programming Across SubsetsTraveling Salesman ProblemColoringDominating Set in bipartite graphs

2 Further Reading

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 21 / 30

Page 28: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Dominating Set

A dominating set in a graph G = (V,E) is a subset of vertices S ⊆ V such thateach vertex of G is either in S or adjacent to a vertex in S.

Dominating SetInput: Graph G, integer kQuestion: Does G have a dominating set of size k?

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 22 / 30

Page 29: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Bipartite graphs

A graph G = (V,E) is bipartite if its vertex set can be partitioned into twoindependent sets.

Dominating Set in Bipartite GraphsInput: Bipartite graph G, integer kQuestion: Does G have a dominating set of size k?

Note: Dominating Set in Bipartite Graphs is NP-complete.

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 23 / 30

Page 30: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Algorithm for Dominating Set in Bipartite Graphs I

Partition V into independent sets A and B, with |B| ≥ |A|.

The algorithm has 2 phases:

Preprocessing phase: compute for each X ⊆ A a subset Opt[X] which is asmallest subset of B that dominates X.

Main phase: for each subset X ⊆ A, compute a dominating set D of G ofminimum size such that D ∩A = X.

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 24 / 30

Page 31: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Algorithm for Dominating Set in Bipartite Graphs II

Main phase. For a vertex subset X ⊆ A, a dominating set D of G of minimumsize such that D ∩A = X is obtained by setting

D := X ∪ (B \N(X)) ∪ Opt[A \ (X ∪N(B \N(X)))]

if A \X contains no degree-0 vertex.(If A \X contains a degree-0 vertex, we skip this set X, because there is nodominating set D of G with D ∩A = X.)

A B

N(X)

X

N(B \N(X))

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 25 / 30

Page 32: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Algorithm for Dominating Set in Bipartite Graphs III

Preprocessing phase. Let B = {b1, . . . , b|B|}. We compute for each X ⊆ A andinteger k, 0 ≤ k ≤ |B|, a subset Opt[X, k] ⊆ {b1, . . . , bk} which is defined as

a smallest subset of {b1, . . . , bk} that dominates X if X ⊆ N({b1, . . . , bk}),and

B if X 6⊆ N({b1, . . . , bk}).Note: Opt[X, |B|] = Opt[X].

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 26 / 30

Page 33: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Algorithm for Dominating Set in Bipartite Graphs IV

Base cases

Opt[∅, k] = ∅ ∀k ∈ {0, . . . , |B|},Opt[X, 0] = B ∀X, ∅ ( X ⊆ A.

Dynamic Programming recurrence

Opt[X, k] =

{Opt[X, k − 1] if |Opt[X, k − 1]| < 1 + |Opt[X \N(bk), k − 1]|{bk} ∪ Opt[X \N(bk), k − 1] otherwise

for each X, ∅ ( X ⊆ A and k ∈ {1, . . . , |B|}.

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 27 / 30

Page 34: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Algorithm for Dominating Set in Bipartite Graphs V

Theorem 7 ([Liedloff ’08])

Dominating Set in Bipartite Graphs can be solved in O∗(2n/2) time,where n is the number of vertices of the input graph.

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 28 / 30

Page 35: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Outline

1 Dynamic Programming Across SubsetsTraveling Salesman ProblemColoringDominating Set in bipartite graphs

2 Further Reading

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 29 / 30

Page 36: 2. Dynamic Programming - COMP6741: Parameterized and …2. Dynamic Programming COMP6741: Parameterized and Exact Computation Serge Gaspers12 1School of Computer Science and Engineering,

Further Reading

Chapter 3, Dynamic Programming inFedor V. Fomin and Dieter Kratsch. Exact Exponential Algorithms. Springer,2010.

S. Gaspers (UNSW) Dynamic Programming Semester 2, 2015 30 / 30