116
Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 1 / 46

Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Embed Size (px)

Citation preview

Page 1: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Parametrized AlgorithmsPart 1

�ukasz Kowalik and Marcin Pilipczuk

Warsaw, Poland,21.05.2018

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 1 / 46

Page 2: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Overview

1 A motivating example, de�nition of classes FPT, XP.

2 Technique: branching

3 Technique: kernelization

4 Technique: color coding

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 2 / 46

Page 3: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

The book

Everything can be found in

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 3 / 46

Page 4: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Motivation

We would like to solve NP-hard problems e�ciently.

We are not interested in approximation, heuristics, etc.

We want exact solutions, with provable guarantees.

(Unless P=NP) we cannot solve all instances fast; let us just solve thesimple ones fast.

Which istances are simple?

What do we mean by fast?

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 4 / 46

Page 5: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Parameterized algorithms - example

There were 104 measurements performed, each of them can reportwrong output with probability p ≤ 0.1%.

Create a graph G = (V ,E ):I Vertices are measurements.I u and v adjacent if measurements u and v contradict each other.

We want to �nd minimum sized subset X of measurements such thatmeasurements in V \ X are non-contradictory.

We expect |X | ≤ 10.

The number 10 can be treated as a measure of hardness of theinstance.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 5 / 46

Page 6: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex cover

Vertex cover of a graph G = (V ,E ) is a set S ⊆ V which touches alledges, i.e. for every uv ∈ E we have u ∈ S or v ∈ S .

Decision problem

Input: Graph G = (V ,E ), a number k ∈ N.Does G admit a vertex cover of size ≤ k?

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 6 / 46

Page 7: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex cover: algorithm in time O∗(2k |E |)

Decision problem

Input: Graph G = (V ,E ), a number k ∈ N.Does G admit a vertex cover of size ≤ k?

Exhaustive search in time O(nk · |E |)VertexCover(G = (V ,E ),k)

1: for each X ⊆ V , |X | = k do

2: if all edges incident to X return YES

3: return NO

Not very good for k = 10.

Greedy improvements (pick vertices of maximum degree) do not help.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 7 / 46

Page 8: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex cover: algorithm in time O∗(2k |E |)

Decision problem

Input: Graph G = (V ,E ), a number k ∈ N.Does G admit a vertex cover of size ≤ k?

Exhaustive search in time O(nk · |E |)VertexCover(G = (V ,E ),k)

1: for each X ⊆ V , |X | = k do

2: if all edges incident to X return YES

3: return NO

Not very good for k = 10.

Greedy improvements (pick vertices of maximum degree) do not help.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 7 / 46

Page 9: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex cover: algorithm in time O∗(2k |E |)

Decision problem

Input: Graph G = (V ,E ), a number k ∈ N.Does G admit a vertex cover of size ≤ k?

Branching algorithm in time O∗(2k |E |)VertexCover(G = (V ,E ),k)

1: if E = ∅ return YES2: if k = 0 return NO3: Pick any edge uv ∈ E4: VertexCover(G − u,k − 1) or VertexCover(G − v ,k − 1)

Reasonable running time for k = 10.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 7 / 46

Page 10: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Parameterized decision problems

Let Σ be a �nite alphabet. Say, Σ = {0, 1}.

(Classical) decision problem

Decision problem is any subset L of words over Σ, i.e., L ⊆ Σ∗.

Intuition: L is a set of (binary encodings of) YES-instances.

Example: VertexCover is a set of binary encodings of pairs (G , k) suchthat G admits a vertex cover of size k .

Parameterized decision problem

Parameterized decision problem is any subset L ⊆ Σ∗ × N.

For an instance (x , k) ∈ Σ∗ × N, k is called a parameter.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 8 / 46

Page 11: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Parameterized decision problems: examples

Vertex cover parameterized by the solution size

L = {(e(G ), k) : G admits a vertex cover of size k}; e is an encoding

Clique parameterized by the maximum degree

L = {((G , k),∆) : G contains a clique of size k and ∆ = ∆(G )}

Independent Set parameterized by treewidth (to be de�ned)

L = {((G , k), t) :G admits an independent set of size k and G has treewidth t}

The central question of this course:

How does the complexity of a parameterized problem depend on

the parameter?

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 9 / 46

Page 12: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Parameterized decision problems: examples

Vertex cover parameterized by the solution size

L = {(G , k) : G admits a vertex cover of size k}

Clique parameterized by the maximum degree

L = {((G , k),∆) : G contains a clique of size k and ∆ = ∆(G )}

Independent Set parameterized by treewidth (to be de�ned)

L = {((G , k), t) :G admits an independent set of size k and G has treewidth t}

The central question of this course:

How does the complexity of a parameterized problem depend on

the parameter?

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 9 / 46

Page 13: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Parameterized decision problems: examples

Vertex cover parameterized by the solution size

L = {(G , k) : G admits a vertex cover of size k}

Clique parameterized by the maximum degree

L = {((G , k),∆) : G contains a clique of size k and ∆ = ∆(G )}

Independent Set parameterized by treewidth (to be de�ned)

L = {((G , k), t) :G admits an independent set of size k and G has treewidth t}

The central question of this course:

How does the complexity of a parameterized problem depend on

the parameter?

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 9 / 46

Page 14: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Parameterized decision problems: examples

Vertex cover parameterized by the solution size

L = {(G , k) : G admits a vertex cover of size k}

Clique parameterized by the maximum degree

L = {((G , k),∆) : G contains a clique of size k and ∆ = ∆(G )}

Independent Set parameterized by treewidth (to be de�ned)

L = {((G , k), t) :G admits an independent set of size k and G has treewidth t}

The central question of this course:

How does the complexity of a parameterized problem depend on

the parameter?

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 9 / 46

Page 15: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Parameterized decision problems: examples

Vertex cover parameterized by the solution size

L = {(G , k) : G admits a vertex cover of size k}

Clique parameterized by the maximum degree

L = {((G , k),∆) : G contains a clique of size k and ∆ = ∆(G )}

Independent Set parameterized by treewidth (to be de�ned)

L = {((G , k), t) :G admits an independent set of size k and G has treewidth t}

The central question of this course:

How does the complexity of a parameterized problem depend on

the parameter?

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 9 / 46

Page 16: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Parameterized algorithm: de�nitionLet L be a parameterized problem.

Parameterized algorithm

Algorithm A is a parameterized algorithm for L ifthere is a computable function f : N→ Nand a constant c such thatfor every (x , k) ∈ Σ∗ × N, algorithm A correctly decides if (x , k) ∈ L intime f (k) · ncwhere n = |(x , k)| is the size of the instance.

Problem L is then called �xed parameter tractable (FPT)

A is also called FPT algorithm.

Class of decision problems:

FPT = {L ⊆ Σ∗ × N : L admits an FPT algorithm}

Note: P ⊆ FPT, but FPT 6⊆ NP.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 10 / 46

Page 17: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Parameterized algorithm: de�nitionLet L be a parameterized problem.

Parameterized algorithm

Algorithm A is a parameterized algorithm for L ifthere is a computable function f : N→ N such thatfor every (x , k) ∈ Σ∗ × N, algorithm A correctly decides if (x , k) ∈ L intime f (k) · nO(1)

where n = |(x , k)| is the size of the instance.

Problem L is then called �xed parameter tractable (FPT)

A is also called FPT algorithm.

Class of decision problems:

FPT = {L ⊆ Σ∗ × N : L admits an FPT algorithm}

Note: P ⊆ FPT, but FPT 6⊆ NP.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 10 / 46

Page 18: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Parameterized algorithm: de�nitionLet L be a parameterized problem.

Parameterized algorithm

Algorithm A is a parameterized algorithm for L ifthere is a computable function f : N→ N such thatfor every (x , k) ∈ Σ∗ × N, algorithm A correctly decides if (x , k) ∈ L intime f (k) · nO(1)

where n = |(x , k)| is the size of the instance.

Examples: time O(2kn), O(k! · n15), O(10k + n3), O(22kn3),

O(222k

n5), O(222···2︸︷︷︸

k times

n2)

BAD examples: O(2nk), O(nk), O(nlog log k)

Problem L is then called �xed parameter tractable (FPT)

A is also called FPT algorithm.Class of decision problems:

FPT = {L ⊆ Σ∗ × N : L admits an FPT algorithm}

Note: P ⊆ FPT, but FPT 6⊆ NP.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 10 / 46

Page 19: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Parameterized algorithm: de�nitionLet L be a parameterized problem.

Parameterized algorithm

Algorithm A is a parameterized algorithm for L ifthere is a computable function f : N→ N such thatfor every (x , k) ∈ Σ∗ × N, algorithm A correctly decides if (x , k) ∈ L intime f (k) · nO(1)

where n = |(x , k)| is the size of the instance.

Problem L is then called �xed parameter tractable (FPT)

A is also called FPT algorithm.

Class of decision problems:

FPT = {L ⊆ Σ∗ × N : L admits an FPT algorithm}

Note: P ⊆ FPT, but FPT 6⊆ NP.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 10 / 46

Page 20: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Parameterized algorithm: de�nitionLet L be a parameterized problem.

Parameterized algorithm

Algorithm A is a parameterized algorithm for L ifthere is a computable function f : N→ N such thatfor every (x , k) ∈ Σ∗ × N, algorithm A correctly decides if (x , k) ∈ L intime f (k) · nO(1)

where n = |(x , k)| is the size of the instance.

Problem L is then called �xed parameter tractable (FPT)

A is also called FPT algorithm.

Class of decision problems:

FPT = {L ⊆ Σ∗ × N : L admits an FPT algorithm}

Note: P ⊆ FPT, but FPT 6⊆ NP.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 10 / 46

Page 21: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Parameterized algorithm: de�nitionLet L be a parameterized problem.

Parameterized algorithm

Algorithm A is a parameterized algorithm for L ifthere is a computable function f : N→ N such thatfor every (x , k) ∈ Σ∗ × N, algorithm A correctly decides if (x , k) ∈ L intime f (k) · nO(1)

where n = |(x , k)| is the size of the instance.

Problem L is then called �xed parameter tractable (FPT)

A is also called FPT algorithm.

Class of decision problems:

FPT = {L ⊆ Σ∗ × N : L admits an FPT algorithm}

Note: P ⊆ FPT, but FPT 6⊆ NP.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 10 / 46

Page 22: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Parameterized algorithm: de�nitionLet L be a parameterized problem.

Parameterized algorithm

Algorithm A is a parameterized algorithm for L ifthere is a computable function f : N→ N such thatfor every (x , k) ∈ Σ∗ × N, algorithm A correctly decides if (x , k) ∈ L intime f (k) · nO(1)

where n = |(x , k)| is the size of the instance.

Problem L is then called �xed parameter tractable (FPT)

A is also called FPT algorithm.

Class of decision problems:

FPT = {L ⊆ Σ∗ × N : L admits an FPT algorithm}

Note: P ⊆ FPT, but FPT 6⊆ NP.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 10 / 46

Page 23: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Parameterized algorithm: de�nitionLet L be a parameterized problem.

Parameterized algorithm

Algorithm A is a parameterized algorithm for L ifthere is a computable function f : N→ N such thatfor every (x , k) ∈ Σ∗ × N, algorithm A correctly decides if (x , k) ∈ L intime f (k) · nO(1)

where n = |(x , k)| is the size of the instance.

Problem L is then called �xed parameter tractable (FPT)

A is also called FPT algorithm.

Class of decision problems:

FPT = {L ⊆ Σ∗ × N : L admits an FPT algorithm}

Note: P ⊆ FPT, but FPT 6⊆ NP.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 10 / 46

Page 24: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

XP algorithm: de�nitionLet L be a parameterized problem.

XP algorithm

Algorithm A is an XP algorithm for L ifthere are two computable functions f , g : N→ N such thatfor every (x , k) ∈ Σ∗ × N, algorithm A correctly decides if (x , k) ∈ L intime f (k) · ng(k)where n = |(x , k)| is the size of the instance.

think: polynomial for every �xed k .

Examples: time O(2kn), O(222···2︸︷︷︸

k times

n2), O(nlog log k), O(nk), O(n22k

).

BAD examples: O(2nk), O(kn)

Class of decision problems:

XP = {L ⊆ Σ∗ × N : L admits an XP algorithm}

Note: P ⊆ FPT ⊆ XP.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 11 / 46

Page 25: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

XP algorithm: de�nitionLet L be a parameterized problem.

XP algorithm

Algorithm A is an XP algorithm for L ifthere are two computable functions f , g : N→ N such thatfor every (x , k) ∈ Σ∗ × N, algorithm A correctly decides if (x , k) ∈ L intime f (k) · ng(k)where n = |(x , k)| is the size of the instance.

think: polynomial for every �xed k .

Examples: time O(2kn), O(222···2︸︷︷︸

k times

n2), O(nlog log k), O(nk), O(n22k

).

BAD examples: O(2nk), O(kn)

Class of decision problems:

XP = {L ⊆ Σ∗ × N : L admits an XP algorithm}

Note: P ⊆ FPT ⊆ XP.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 11 / 46

Page 26: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

XP algorithm: de�nitionLet L be a parameterized problem.

XP algorithm

Algorithm A is an XP algorithm for L ifthere are two computable functions f , g : N→ N such thatfor every (x , k) ∈ Σ∗ × N, algorithm A correctly decides if (x , k) ∈ L intime f (k) · ng(k)where n = |(x , k)| is the size of the instance.

think: polynomial for every �xed k .

Examples: time O(2kn), O(222···2︸︷︷︸

k times

n2), O(nlog log k), O(nk), O(n22k

).

BAD examples: O(2nk), O(kn)

Class of decision problems:

XP = {L ⊆ Σ∗ × N : L admits an XP algorithm}

Note: P ⊆ FPT ⊆ XP.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 11 / 46

Page 27: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

XP algorithm: de�nitionLet L be a parameterized problem.

XP algorithm

Algorithm A is an XP algorithm for L ifthere are two computable functions f , g : N→ N such thatfor every (x , k) ∈ Σ∗ × N, algorithm A correctly decides if (x , k) ∈ L intime f (k) · ng(k)where n = |(x , k)| is the size of the instance.

think: polynomial for every �xed k .

Examples: time O(2kn), O(222···2︸︷︷︸

k times

n2), O(nlog log k), O(nk), O(n22k

).

BAD examples: O(2nk), O(kn)

Class of decision problems:

XP = {L ⊆ Σ∗ × N : L admits an XP algorithm}

Note: P ⊆ FPT ⊆ XP.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 11 / 46

Page 28: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

XP algorithm: de�nitionLet L be a parameterized problem.

XP algorithm

Algorithm A is an XP algorithm for L ifthere are two computable functions f , g : N→ N such thatfor every (x , k) ∈ Σ∗ × N, algorithm A correctly decides if (x , k) ∈ L intime f (k) · ng(k)where n = |(x , k)| is the size of the instance.

think: polynomial for every �xed k .

Examples: time O(2kn), O(222···2︸︷︷︸

k times

n2), O(nlog log k), O(nk), O(n22k

).

BAD examples: O(2nk), O(kn)

Class of decision problems:

XP = {L ⊆ Σ∗ × N : L admits an XP algorithm}

Note: P ⊆ FPT ⊆ XP.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 11 / 46

Page 29: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

XP algorithm: de�nitionLet L be a parameterized problem.

XP algorithm

Algorithm A is an XP algorithm for L ifthere are two computable functions f , g : N→ N such thatfor every (x , k) ∈ Σ∗ × N, algorithm A correctly decides if (x , k) ∈ L intime f (k) · ng(k)where n = |(x , k)| is the size of the instance.

think: polynomial for every �xed k .

Examples: time O(2kn), O(222···2︸︷︷︸

k times

n2), O(nlog log k), O(nk), O(n22k

).

BAD examples: O(2nk), O(kn)

Class of decision problems:

XP = {L ⊆ Σ∗ × N : L admits an XP algorithm}

Note: P ⊆ FPT ⊆ XP.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 11 / 46

Page 30: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

XP algorithm: de�nitionLet L be a parameterized problem.

XP algorithm

Algorithm A is an XP algorithm for L ifthere are two computable functions f , g : N→ N such thatfor every (x , k) ∈ Σ∗ × N, algorithm A correctly decides if (x , k) ∈ L intime f (k) · ng(k)where n = |(x , k)| is the size of the instance.

think: polynomial for every �xed k .

Examples: time O(2kn), O(222···2︸︷︷︸

k times

n2), O(nlog log k), O(nk), O(n22k

).

BAD examples: O(2nk), O(kn)

Class of decision problems:

XP = {L ⊆ Σ∗ × N : L admits an XP algorithm}

Note: P ⊆ FPT ⊆ XP.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 11 / 46

Page 31: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Why only decision problems?

To simplify algorithms

Typically, it is straightforward to extend the algorithm to make itreturn a solution

Otherwise, there are still ways to extract a solution using the decisionalgorithm multiple times (we will see it later).

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 12 / 46

Page 32: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Why only decision problems?

To simplify algorithms

Typically, it is straightforward to extend the algorithm to make itreturn a solution

Otherwise, there are still ways to extract a solution using the decisionalgorithm multiple times (we will see it later).

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 12 / 46

Page 33: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Why only decision problems?

To simplify algorithms

Typically, it is straightforward to extend the algorithm to make itreturn a solution

Otherwise, there are still ways to extract a solution using the decisionalgorithm multiple times (we will see it later).

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 12 / 46

Page 34: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Technique: branching

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 13 / 46

Page 35: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

General Idea

A recursive algorithm

At every recursive call, we branch into f (k) cases

Depth of the recursion is g(k).

Example: Vertex Cover, f (k) = 2, g(k) = k .

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 14 / 46

Page 36: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

FVS in tournaments

Feedback Vertex Set (FVS) in Tournaments

Input: a tournament (oriented clique) T , integer kQuestion: is there a subset X ⊆ V (T ) of size at most k ,

such that T \ X is acyclic

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 15 / 46

Page 37: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

FVS in tournaments

Feedback Vertex Set (FVS) in Tournaments

Input: a tournament (oriented clique) T , integer kQuestion: is there a subset X ⊆ V (T ) of size at most k ,

such that T \ X is acyclic

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 15 / 46

Page 38: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

FVS in tournaments

Lemma

If a tournament contains a cycle, then it contains a 3-cycle.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 16 / 46

Page 39: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

FVS in tournaments

Lemma

If a tournament contains a cycle, then it contains a 3-cycle.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 16 / 46

Page 40: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

FVS in tournaments

Lemma

If a tournament contains a cycle, then it contains a 3-cycle.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 16 / 46

Page 41: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

FVS in tournaments

Lemma

If a tournament contains a cycle, then it contains a 3-cycle.

Branching algorithm in time O∗(3kn3)

FVS(G = (V ,E ),k)

1: if k < 0 return NO2: if G has no directed 3-cycle return YES3: Let abc be a directed 3-cycle4: return FVS(G − a,k − 1) or FVS(G − b,k − 1) or FVS(G − c ,k − 1)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 17 / 46

Page 42: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Technique: kernelization

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 18 / 46

Page 43: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Kernelization: FPT by preprocessing

NP-hard problem instance

kk

NP-hard problem instance

poly time

size ≤ f (k)want: f (k) = poly(k)

Tikz faces based on a code by Raoul Kessels,http://www.texample.net/tikz/examples/emoticons/,under Creative Commons Attribution 2.5 license (CC BY 2.5)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 19 / 46

Page 44: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Kernelization: FPT by preprocessing

NP-hard problem instance

k

k

NP-hard problem instance

poly time

size ≤ f (k)want: f (k) = poly(k)

Tikz faces based on a code by Raoul Kessels,http://www.texample.net/tikz/examples/emoticons/,under Creative Commons Attribution 2.5 license (CC BY 2.5)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 19 / 46

Page 45: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Kernelization: FPT by preprocessing

NP-hard problem instance

k

k

NP-hard problem instance

poly time

size ≤ f (k)want: f (k) = poly(k)

Tikz faces based on a code by Raoul Kessels,http://www.texample.net/tikz/examples/emoticons/,under Creative Commons Attribution 2.5 license (CC BY 2.5)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 19 / 46

Page 46: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Kernelization: FPT by preprocessing

NP-hard problem instance

k

k

NP-hard problem instance

poly time

size ≤ f (k)want: f (k) = poly(k)

Tikz faces based on a code by Raoul Kessels,http://www.texample.net/tikz/examples/emoticons/,under Creative Commons Attribution 2.5 license (CC BY 2.5)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 19 / 46

Page 47: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Kernelization: FPT by preprocessing

NP-hard problem instance

k

k

NP-hard problem instance

poly time

size ≤ f (k)

want: f (k) = poly(k)

Tikz faces based on a code by Raoul Kessels,http://www.texample.net/tikz/examples/emoticons/,under Creative Commons Attribution 2.5 license (CC BY 2.5)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 19 / 46

Page 48: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Kernelization: FPT by preprocessing

NP-hard problem instance

k

k

NP-hard problem instance

poly time

size ≤ f (k)want: f (k) = poly(k)

Tikz faces based on a code by Raoul Kessels,http://www.texample.net/tikz/examples/emoticons/,under Creative Commons Attribution 2.5 license (CC BY 2.5)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 19 / 46

Page 49: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Kernelization: FPT by preprocessing

NP-hard problem instance

k

k

NP-hard problem instance

poly time

size ≤ f (k)want: f (k) = poly(k)

Kernelization algorithm for a parameterized problem L is anypolynomial-time algorithm which, given an instance (x , k) returns aninstance (x ′, k ′) such that:

(x , k) ∈ L i� (x ′, k ′) ∈ L (equivalence)

|X | = f (k) and k ′ = g(k) for some computable functions f , g .

Tikz faces based on a code by Raoul Kessels,http://www.texample.net/tikz/examples/emoticons/,under Creative Commons Attribution 2.5 license (CC BY 2.5)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 19 / 46

Page 50: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Kernelization: FPT by preprocessing

NP-hard problem instance

k

k

NP-hard problem instance

poly time

size ≤ f (k)want: f (k) = poly(k)

Instead of saying `L has a kernelization algorithm which returns aninstance of size f (k)' we say shortly `L has a kernel of size f (k)'.Kernel of size f (k) for a problem in NP implies FPT algorithm in timeO(exp(poly(f (k))))One can show that an FPT algorithm implies a kernel of size f (k).Usually, we are interested in polynomial kernels (of size kO(1)).

Tikz faces based on a code by Raoul Kessels,http://www.texample.net/tikz/examples/emoticons/,under Creative Commons Attribution 2.5 license (CC BY 2.5)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 19 / 46

Page 51: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Kernelization: FPT by preprocessing

NP-hard problem instance

k

k

NP-hard problem instance

poly time

size ≤ f (k)want: f (k) = poly(k)

Tikz faces based on a code by Raoul Kessels,http://www.texample.net/tikz/examples/emoticons/,under Creative Commons Attribution 2.5 license (CC BY 2.5)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 19 / 46

Page 52: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

A simple kernel for vertex coverKernelization algorithm:

1 While there is v ∈ V with deg(v) > k , remove v and decrease k by 1.

2 While there is v ∈ V with deg(v) = 0, remove v .3 If now |E | > k2 return NO.4 return (G , k).

Running time O(|E |+ |V |).

Theorem

Vertex Cover admits a kernel with at most k2 edges.

Theorem

Vertex Cover admits a kernel with at most 2k2 vertices.

Proof:|V | ≤ 2

∑v∈V

deg(v) = 2|E | ≤ 2k2

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 20 / 46

Page 53: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

A simple kernel for vertex coverKernelization algorithm:

1 While there is v ∈ V with deg(v) > k , remove v and decrease k by 1.Why correct?

(G , k) ∈ VertexCover⇔ (G − v , k − 1) ∈ VertexCover(⇐) Let X ′ be a vertex cover in G − v .

Then X ′ ∪ {v} is a vertex cover of size k in G .

(⇒) Let X be a vertex cover in G , |X | ≤ k .Then X contains v (why?).So X \ {v} is a vertex cover of size ≤ k − 1 in G − v .

2 While there is v ∈ V with deg(v) = 0, remove v .3 If now |E | > k2 return NO.4 return (G , k).

Running time O(|E |+ |V |).

Theorem

Vertex Cover admits a kernel with at most k2 edges.

Theorem

Vertex Cover admits a kernel with at most 2k2 vertices.

Proof:|V | ≤ 2

∑v∈V

deg(v) = 2|E | ≤ 2k2

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 20 / 46

Page 54: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

A simple kernel for vertex coverKernelization algorithm:

1 While there is v ∈ V with deg(v) > k , remove v and decrease k by 1.2 While there is v ∈ V with deg(v) = 0, remove v .

3 If now |E | > k2 return NO.4 return (G , k).

Running time O(|E |+ |V |).

Theorem

Vertex Cover admits a kernel with at most k2 edges.

Theorem

Vertex Cover admits a kernel with at most 2k2 vertices.

Proof:|V | ≤ 2

∑v∈V

deg(v) = 2|E | ≤ 2k2

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 20 / 46

Page 55: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

A simple kernel for vertex coverKernelization algorithm:

1 While there is v ∈ V with deg(v) > k , remove v and decrease k by 1.2 While there is v ∈ V with deg(v) = 0, remove v . Why correct?

(G , k) ∈ VertexCover⇔ (G − v , k) ∈ VertexCover(⇐) Let X ′ be a vertex cover of size k in G − v .

Then X ′ is a vertex cover of size k in G .

(⇒) Let X be a minimum vertex cover in G , |X | ≤ k .Then v 6∈ X (why?).So X is a vertex cover of size ≤ k in G − v .

3 If now |E | > k2 return NO.4 return (G , k).

Running time O(|E |+ |V |).

Theorem

Vertex Cover admits a kernel with at most k2 edges.

Theorem

Vertex Cover admits a kernel with at most 2k2 vertices.

Proof:|V | ≤ 2

∑v∈V

deg(v) = 2|E | ≤ 2k2

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 20 / 46

Page 56: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

A simple kernel for vertex coverKernelization algorithm:

1 While there is v ∈ V with deg(v) > k , remove v and decrease k by 1.2 While there is v ∈ V with deg(v) = 0, remove v .3 If now |E | > k2 return NO.

4 return (G , k).

Running time O(|E |+ |V |).

Theorem

Vertex Cover admits a kernel with at most k2 edges.

Theorem

Vertex Cover admits a kernel with at most 2k2 vertices.

Proof:|V | ≤ 2

∑v∈V

deg(v) = 2|E | ≤ 2k2

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 20 / 46

Page 57: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

A simple kernel for vertex coverKernelization algorithm:

1 While there is v ∈ V with deg(v) > k , remove v and decrease k by 1.2 While there is v ∈ V with deg(v) = 0, remove v .3 If now |E | > k2 return NO. Why correct?

If YES, i.e., exists a vertex cover X , |X | ≤ k then

|E | ≤∑x∈X

deg(x) ≤∑x∈X

k ≤ k2.

4 return (G , k).

Running time O(|E |+ |V |).

Theorem

Vertex Cover admits a kernel with at most k2 edges.

Theorem

Vertex Cover admits a kernel with at most 2k2 vertices.

Proof:|V | ≤ 2

∑v∈V

deg(v) = 2|E | ≤ 2k2

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 20 / 46

Page 58: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

A simple kernel for vertex coverKernelization algorithm:

1 While there is v ∈ V with deg(v) > k , remove v and decrease k by 1.2 While there is v ∈ V with deg(v) = 0, remove v .3 If now |E | > k2 return NO.4 return (G , k).

Running time O(|E |+ |V |).

Theorem

Vertex Cover admits a kernel with at most k2 edges.

Theorem

Vertex Cover admits a kernel with at most 2k2 vertices.

Proof:|V | ≤ 2

∑v∈V

deg(v) = 2|E | ≤ 2k2

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 20 / 46

Page 59: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

A simple kernel for vertex coverKernelization algorithm:

1 While there is v ∈ V with deg(v) > k , remove v and decrease k by 1.2 While there is v ∈ V with deg(v) = 0, remove v .3 If now |E | > k2 return NO.4 return (G , k).

Running time O(|E |+ |V |).

Theorem

Vertex Cover admits a kernel with at most k2 edges.

Theorem

Vertex Cover admits a kernel with at most 2k2 vertices.

Proof:|V | ≤ 2

∑v∈V

deg(v) = 2|E | ≤ 2k2

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 20 / 46

Page 60: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

A simple kernel for vertex coverKernelization algorithm:

1 While there is v ∈ V with deg(v) > k , remove v and decrease k by 1.2 While there is v ∈ V with deg(v) = 0, remove v .3 If now |E | > k2 return NO.4 return (G , k).

Running time O(|E |+ |V |).

Theorem

Vertex Cover admits a kernel with at most k2 edges.

Theorem

Vertex Cover admits a kernel with at most 2k2 vertices.

Proof:|V | ≤ 2

∑v∈V

deg(v) = 2|E | ≤ 2k2

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 20 / 46

Page 61: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

A simple kernel for vertex coverKernelization algorithm:

1 While there is v ∈ V with deg(v) > k , remove v and decrease k by 1.2 While there is v ∈ V with deg(v) = 0, remove v .3 If now |E | > k2 return NO.4 return (G , k).

Running time O(|E |+ |V |).

Theorem

Vertex Cover admits a kernel with at most k2 edges.

Theorem

Vertex Cover admits a kernel with at most 2k2 vertices.

Proof:|V | ≤ 2

∑v∈V

deg(v) = 2|E | ≤ 2k2

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 20 / 46

Page 62: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

FPT algorithms from the kernel

Theorem

Vertex Cover admits a kernel with at most 2k2 vertices, and it can becomputed in time O(|E |+ |V |).

Exhaustive search:(2k2

k

)= kO(k).

Whole FPT algorithm: O(|E |+ |V |+ kO(k))

Branching: 2k · k . Whole FPT algorithm: |E |+ |V |+ 2k · k .Compare with O(|E |+ 2k · |V |)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 21 / 46

Page 63: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Kernel of size 2k vertices for VertexCoverConsider the standard integer linear program for �nding minimum vertexcover.

min∑

v∈V xvxu + xv ≥ 1 for each uv ∈ Exv ≥ 0 for each v ∈ V .xv ∈ Z for each v ∈ V .

... and its relaxation (a linear program):

min∑

v∈V xvxu + xv ≥ 1 for each uv ∈ Exv ≥ 0 for each v ∈ V .

Theorem (Khachiyan 1979)

Linear programming admits a polynomial time algorithm.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 22 / 46

Page 64: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Kernel of size 2k vertices for VertexCoverConsider the standard integer linear program for �nding minimum vertexcover.

min∑

v∈V xvxu + xv ≥ 1 for each uv ∈ Exv ≥ 0 for each v ∈ V .xv ∈ Z for each v ∈ V .

... and its relaxation (a linear program):

min∑

v∈V xvxu + xv ≥ 1 for each uv ∈ Exv ≥ 0 for each v ∈ V .

Theorem (Khachiyan 1979)

Linear programming admits a polynomial time algorithm.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 22 / 46

Page 65: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP

cost: n − 1

cost: n/2

Vertex Cover LP

min

∑v∈V (G)

xv

s.t. xu + xv ≥ 1 ∀uv∈E(G)

xv ≥ 0 ∀v∈V (G)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 23 / 46

Page 66: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP

cost: n − 1

cost: n/2

Vertex Cover LP

min

∑v∈V (G)

xv

s.t. xu + xv ≥ 1 ∀uv∈E(G)

xv ≥ 0 ∀v∈V (G)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 23 / 46

Page 67: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP

cost: n − 1

cost: n/2

Vertex Cover LP

min

∑v∈V (G)

xv

s.t. xu + xv ≥ 1 ∀uv∈E(G)

xv ≥ 0 ∀v∈V (G)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 23 / 46

Page 68: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP: vertex classes

xv = 0 ⇐⇒ v ∈ V0

0 < xv <1

2⇐⇒ v ∈ Vε

xv = 1

2⇐⇒ v ∈ V 1

2

1

2< xv < 1 ⇐⇒ v ∈ V1−ε

xv = 1 ⇐⇒ v ∈ V1

V< 1

2

= V0 ∪ Vε

V> 1

2

= V1 ∪ V1−ε

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 24 / 46

Page 69: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP: analysis

+ε −ε1 V< 1

2

independent, E (V< 1

2

,V 1

2

) = ∅,⇒ ∀v∈V

< 1

2

N(v) ⊆ V> 1

2

.

2 |V< 1

2

| ≥ |V> 1

2

|,otherwise +ε on V< 1

2

, −ε on V> 1

2

.

3 ∀X⊆V> 1

2

|X | ≤ |N(X ) ∩ V< 1

2

|,otherwise +ε on N(X ) ∩ V< 1

2

, −ε on X .

4 Hall's theorem⇒ matching saturating V> 1

2

.

5 Greedily take V> 1

2

and discard V< 1

2

.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 25 / 46

Page 70: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP: analysis

+ε −ε

1 V< 1

2

independent, E (V< 1

2

,V 1

2

) = ∅,⇒ ∀v∈V

< 1

2

N(v) ⊆ V> 1

2

.

2 |V< 1

2

| ≥ |V> 1

2

|,otherwise +ε on V< 1

2

, −ε on V> 1

2

.

3 ∀X⊆V> 1

2

|X | ≤ |N(X ) ∩ V< 1

2

|,otherwise +ε on N(X ) ∩ V< 1

2

, −ε on X .

4 Hall's theorem⇒ matching saturating V> 1

2

.

5 Greedily take V> 1

2

and discard V< 1

2

.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 25 / 46

Page 71: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP: analysis

+ε −ε1 V< 1

2

independent, E (V< 1

2

,V 1

2

) = ∅,⇒ ∀v∈V

< 1

2

N(v) ⊆ V> 1

2

.

2 |V< 1

2

| ≥ |V> 1

2

|,otherwise +ε on V< 1

2

, −ε on V> 1

2

.

3 ∀X⊆V> 1

2

|X | ≤ |N(X ) ∩ V< 1

2

|,otherwise +ε on N(X ) ∩ V< 1

2

, −ε on X .

4 Hall's theorem⇒ matching saturating V> 1

2

.

5 Greedily take V> 1

2

and discard V< 1

2

.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 25 / 46

Page 72: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP: analysis

+ε −ε1 V< 1

2

independent, E (V< 1

2

,V 1

2

) = ∅,⇒ ∀v∈V

< 1

2

N(v) ⊆ V> 1

2

.

2 |V< 1

2

| ≥ |V> 1

2

|,otherwise +ε on V< 1

2

, −ε on V> 1

2

.

3 ∀X⊆V> 1

2

|X | ≤ |N(X ) ∩ V< 1

2

|,otherwise +ε on N(X ) ∩ V< 1

2

, −ε on X .

4 Hall's theorem⇒ matching saturating V> 1

2

.

5 Greedily take V> 1

2

and discard V< 1

2

.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 25 / 46

Page 73: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP: analysis

+ε −ε

1 V< 1

2

independent, E (V< 1

2

,V 1

2

) = ∅,⇒ ∀v∈V

< 1

2

N(v) ⊆ V> 1

2

.

2 |V< 1

2

| ≥ |V> 1

2

|,otherwise +ε on V< 1

2

, −ε on V> 1

2

.

3 ∀X⊆V> 1

2

|X | ≤ |N(X ) ∩ V< 1

2

|,otherwise +ε on N(X ) ∩ V< 1

2

, −ε on X .

4 Hall's theorem⇒ matching saturating V> 1

2

.

5 Greedily take V> 1

2

and discard V< 1

2

.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 25 / 46

Page 74: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP: analysis

+ε −ε

1 V< 1

2

independent, E (V< 1

2

,V 1

2

) = ∅,⇒ ∀v∈V

< 1

2

N(v) ⊆ V> 1

2

.

2 |V< 1

2

| ≥ |V> 1

2

|,otherwise +ε on V< 1

2

, −ε on V> 1

2

.

3 ∀X⊆V> 1

2

|X | ≤ |N(X ) ∩ V< 1

2

|,otherwise +ε on N(X ) ∩ V< 1

2

, −ε on X .

4 Hall's theorem⇒ matching saturating V> 1

2

.

5 Greedily take V> 1

2

and discard V< 1

2

.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 25 / 46

Page 75: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP: analysis

−ε +ε+ε −ε

1 E (V0,V1−ε) = ∅,⇒ N(V1−ε) ∩ V< 1

2

⊆ Vε.

2 if |V1−ε| ≤ |Vε|, thenwe can +ε on V1−ε, −ε on Vε.

3 if |V1−ε| ≥ |Vε|, thenwe can +ε on Vε, −ε on V1−ε.

4 conclusion: there exists LP optimum withV = V0 ∪ V 1

2

∪ V1.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 26 / 46

Page 76: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP: analysis

−ε +ε+ε −ε

1 E (V0,V1−ε) = ∅,⇒ N(V1−ε) ∩ V< 1

2

⊆ Vε.

2 if |V1−ε| ≤ |Vε|, thenwe can +ε on V1−ε, −ε on Vε.

3 if |V1−ε| ≥ |Vε|, thenwe can +ε on Vε, −ε on V1−ε.

4 conclusion: there exists LP optimum withV = V0 ∪ V 1

2

∪ V1.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 26 / 46

Page 77: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP: analysis

−ε +ε

+ε −ε

1 E (V0,V1−ε) = ∅,⇒ N(V1−ε) ∩ V< 1

2

⊆ Vε.

2 if |V1−ε| ≤ |Vε|, thenwe can +ε on V1−ε, −ε on Vε.

3 if |V1−ε| ≥ |Vε|, thenwe can +ε on Vε, −ε on V1−ε.

4 conclusion: there exists LP optimum withV = V0 ∪ V 1

2

∪ V1.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 26 / 46

Page 78: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP: analysis

−ε +ε

+ε −ε

1 E (V0,V1−ε) = ∅,⇒ N(V1−ε) ∩ V< 1

2

⊆ Vε.

2 if |V1−ε| ≤ |Vε|, thenwe can +ε on V1−ε, −ε on Vε.

3 if |V1−ε| ≥ |Vε|, thenwe can +ε on Vε, −ε on V1−ε.

4 conclusion: there exists LP optimum withV = V0 ∪ V 1

2

∪ V1.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 26 / 46

Page 79: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP: analysis

−ε +ε+ε −ε

1 E (V0,V1−ε) = ∅,⇒ N(V1−ε) ∩ V< 1

2

⊆ Vε.

2 if |V1−ε| ≤ |Vε|, thenwe can +ε on V1−ε, −ε on Vε.

3 if |V1−ε| ≥ |Vε|, thenwe can +ε on Vε, −ε on V1−ε.

4 conclusion: there exists LP optimum withV = V0 ∪ V 1

2

∪ V1.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 26 / 46

Page 80: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP: summary of analysis

1 There exists LP optimum with V = V0 ∪ V 1

2

∪ V1.I Half-integrality

2 If V 1

2

6= V , then we can reduce something.I Take V1 into solution, and discard V0.

unique LP optimum

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 27 / 46

Page 81: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Vertex Cover LP: summary of analysis

1 There exists LP optimum with V = V0 ∪ V 1

2

∪ V1.I Half-integrality

2 If V 1

2

6= V , then we can reduce something.I Take V1 into solution, and discard V0.

unique LP optimum

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 27 / 46

Page 82: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Kernel of size 2k vertices for VertexCover

Theorem (Nemhauser, Trotter 1974)

Let {xv}v∈V be any optimal solution of thevertex cover LP. Partition V :

V0 = {v ∈ V (G ) : xv <12},

V1/2 = {v ∈ V (G ) : xv = 12},

V1 = {v ∈ V (G ) : xv >12}.

Then there is a minimum vertex cover S ofG such that V1 ⊆ S , V0 ∩ S = ∅.

Vertex Cover LP:

min∑

v∈V xv∀ uv ∈ E xu + xv ≥ 1∀ v ∈ V xv ≥ 0.

(G , k) ∈ VertexCover⇔ (G [V1/2], k − |V1|) ∈ VertexCover(⇒) Since V1 ⊆ S and |S | ≤ k we have |S \ X1|=|S | − |V1|≤k − |V1|.

Also, S \ V1 is a vertex cover in G [V1/2]. (check it!)

(⇐) Let X ′ be a vertex cover of size ≤ k − |V1| in G [V1/2].Then X ′ ∪ V1 is a vertex cover of size ≤ k in G (check it!).

Kernelization algorithm:1 Solve the vertex cover LP and get an optimal solution {xv}v∈V .2 If |V1/2| > 2k return NO.3 return (G [V1/2], k − |V1|).

Theorem

Vertex cover admits a kernel of vertex size at most 2k .

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 28 / 46

Page 83: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Kernel of size 2k vertices for VertexCover

Theorem (Nemhauser, Trotter 1974)

Let {xv}v∈V be any optimal solution of thevertex cover LP. Partition V :

V0 = {v ∈ V (G ) : xv <12},

V1/2 = {v ∈ V (G ) : xv = 12},

V1 = {v ∈ V (G ) : xv >12}.

Then there is a minimum vertex cover S ofG such that V1 ⊆ S , V0 ∩ S = ∅.

Vertex Cover LP:

min∑

v∈V xv∀ uv ∈ E xu + xv ≥ 1∀ v ∈ V xv ≥ 0.

Kernelization algorithm:1 Solve the vertex cover LP and get an optimal solution {xv}v∈V .2 If |V1/2| > 2k return NO.

3 return (G [V1/2], k − |V1|).

Theorem

Vertex cover admits a kernel of vertex size at most 2k .

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 28 / 46

Page 84: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Kernel of size 2k vertices for VertexCover

Theorem (Nemhauser, Trotter 1974)

Let {xv}v∈V be any optimal solution of thevertex cover LP. Partition V :

V0 = {v ∈ V (G ) : xv <12},

V1/2 = {v ∈ V (G ) : xv = 12},

V1 = {v ∈ V (G ) : xv >12}.

Then there is a minimum vertex cover S ofG such that V1 ⊆ S , V0 ∩ S = ∅.

Vertex Cover LP:

min∑

v∈V xv∀ uv ∈ E xu + xv ≥ 1∀ v ∈ V xv ≥ 0.

Kernelization algorithm:1 Solve the vertex cover LP and get an optimal solution {xv}v∈V .2 If |V1/2| > 2k return NO. Why correct?

Then,∑

v∈V xv > k , so the integral solution has also value > k .

3 return (G [V1/2], k − |V1|).

Theorem

Vertex cover admits a kernel of vertex size at most 2k .

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 28 / 46

Page 85: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Kernel of size 2k vertices for VertexCover

Theorem (Nemhauser, Trotter 1974)

Let {xv}v∈V be any optimal solution of thevertex cover LP. Partition V :

V0 = {v ∈ V (G ) : xv <12},

V1/2 = {v ∈ V (G ) : xv = 12},

V1 = {v ∈ V (G ) : xv >12}.

Then there is a minimum vertex cover S ofG such that V1 ⊆ S , V0 ∩ S = ∅.

Vertex Cover LP:

min∑

v∈V xv∀ uv ∈ E xu + xv ≥ 1∀ v ∈ V xv ≥ 0.

Kernelization algorithm:1 Solve the vertex cover LP and get an optimal solution {xv}v∈V .2 If |V1/2| > 2k return NO.3 return (G [V1/2], k − |V1|).

Theorem

Vertex cover admits a kernel of vertex size at most 2k .

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 28 / 46

Page 86: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Kernel of size 2k vertices for VertexCover

Theorem (Nemhauser, Trotter 1974)

Let {xv}v∈V be any optimal solution of thevertex cover LP. Partition V :

V0 = {v ∈ V (G ) : xv <12},

V1/2 = {v ∈ V (G ) : xv = 12},

V1 = {v ∈ V (G ) : xv >12}.

Then there is a minimum vertex cover S ofG such that V1 ⊆ S , V0 ∩ S = ∅.

Vertex Cover LP:

min∑

v∈V xv∀ uv ∈ E xu + xv ≥ 1∀ v ∈ V xv ≥ 0.

Kernelization algorithm:1 Solve the vertex cover LP and get an optimal solution {xv}v∈V .2 If |V1/2| > 2k return NO.3 return (G [V1/2], k − |V1|).

Theorem

Vertex cover admits a kernel of vertex size at most 2k .

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 28 / 46

Page 87: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

A few examples of kernels

The problems below ask for a set vertices of size k and k is the parameter.Size of the kernel = number of vertices.

VertexCover: 2k

Feedback Vertex Set: O(k2)

Odd Cycle Transversal: kO(1)

For planar graphs:

Dominating Set 67k ,

Feedback Vertex Set 13k ,

Induced Matching 28k ,

Connected Vertex Cover113k ,

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 29 / 46

Page 88: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Technique: color coding

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 30 / 46

Page 89: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

k-Path problem

Problem

Input: Directed graph G = (V ,E ), k ∈ N.Question: Does G contain a simple path on k vertices?

History

NP-complete (why?)

no trivial FPT algorithm,

Monien 1985: k!nO(1) using representative sets

Bodlaender 1989: k!2knO(1) using treewidth

Alon, Yuster, Zwick 1994: O((2e)k |E |) by color coding

Kneis, Mölle, Richter, Rossmanith 2006: 4knO(1) by color coding

Koutis 2008: 23/2knO(1) by group algebras

Williams 2009: 2knO(1) by group algebras

Björklund, Husfeldt, Kaski, Koivisto 2010: 1.66knO(1), undirected!

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 31 / 46

Page 90: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

k-Path problem

Problem

Input: Directed graph G = (V ,E ), k ∈ N.Question: Does G contain a simple path on k vertices?

History

NP-complete (why?)

no trivial FPT algorithm,

Monien 1985: k!nO(1) using representative sets

Bodlaender 1989: k!2knO(1) using treewidth

Alon, Yuster, Zwick 1994: O((2e)k |E |) by color coding

Kneis, Mölle, Richter, Rossmanith 2006: 4knO(1) by color coding

Koutis 2008: 23/2knO(1) by group algebras

Williams 2009: 2knO(1) by group algebras

Björklund, Husfeldt, Kaski, Koivisto 2010: 1.66knO(1), undirected!

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 31 / 46

Page 91: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

k-Path problem

Problem

Input: Directed graph G = (V ,E ), k ∈ N.Question: Does G contain a simple path on k vertices?

History

NP-complete (why?)

no trivial FPT algorithm,

Monien 1985: k!nO(1) using representative sets

Bodlaender 1989: k!2knO(1) using treewidth

Alon, Yuster, Zwick 1994: O((2e)k |E |) by color coding

Kneis, Mölle, Richter, Rossmanith 2006: 4knO(1) by color coding

Koutis 2008: 23/2knO(1) by group algebras

Williams 2009: 2knO(1) by group algebras

Björklund, Husfeldt, Kaski, Koivisto 2010: 1.66knO(1), undirected!

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 31 / 46

Page 92: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

k-Path problem

Problem

Input: Directed graph G = (V ,E ), k ∈ N.Question: Does G contain a simple path on k vertices?

History

NP-complete (why?)

no trivial FPT algorithm,

Monien 1985: k!nO(1) using representative sets

Bodlaender 1989: k!2knO(1) using treewidth

Alon, Yuster, Zwick 1994: O((2e)k |E |) by color coding

Kneis, Mölle, Richter, Rossmanith 2006: 4knO(1) by color coding

Koutis 2008: 23/2knO(1) by group algebras

Williams 2009: 2knO(1) by group algebras

Björklund, Husfeldt, Kaski, Koivisto 2010: 1.66knO(1), undirected!

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 31 / 46

Page 93: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

k-Path problem

Problem

Input: Directed graph G = (V ,E ), k ∈ N.Question: Does G contain a simple path on k vertices?

History

NP-complete (why?)

no trivial FPT algorithm,

Monien 1985: k!nO(1) using representative sets

Bodlaender 1989: k!2knO(1) using treewidth

Alon, Yuster, Zwick 1994: O((2e)k |E |) by color coding

Kneis, Mölle, Richter, Rossmanith 2006: 4knO(1) by color coding

Koutis 2008: 23/2knO(1) by group algebras

Williams 2009: 2knO(1) by group algebras

Björklund, Husfeldt, Kaski, Koivisto 2010: 1.66knO(1), undirected!

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 31 / 46

Page 94: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

k-Path problem

Problem

Input: Directed graph G = (V ,E ), k ∈ N.Question: Does G contain a simple path on k vertices?

History

NP-complete (why?)

no trivial FPT algorithm,

Monien 1985: k!nO(1) using representative sets

Bodlaender 1989: k!2knO(1) using treewidth

Alon, Yuster, Zwick 1994: O((2e)k |E |) by color coding

Kneis, Mölle, Richter, Rossmanith 2006: 4knO(1) by color coding

Koutis 2008: 23/2knO(1) by group algebras

Williams 2009: 2knO(1) by group algebras

Björklund, Husfeldt, Kaski, Koivisto 2010: 1.66knO(1), undirected!

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 31 / 46

Page 95: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

k-Path problem

Problem

Input: Directed graph G = (V ,E ), k ∈ N.Question: Does G contain a simple path on k vertices?

History

NP-complete (why?)

no trivial FPT algorithm,

Monien 1985: k!nO(1) using representative sets

Bodlaender 1989: k!2knO(1) using treewidth

Alon, Yuster, Zwick 1994: O((2e)k |E |) by color coding

Kneis, Mölle, Richter, Rossmanith 2006: 4knO(1) by color coding

Koutis 2008: 23/2knO(1) by group algebras

Williams 2009: 2knO(1) by group algebras

Björklund, Husfeldt, Kaski, Koivisto 2010: 1.66knO(1), undirected!

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 31 / 46

Page 96: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

k-Path problem

Problem

Input: Directed graph G = (V ,E ), k ∈ N.Question: Does G contain a simple path on k vertices?

History

NP-complete (why?)

no trivial FPT algorithm,

Monien 1985: k!nO(1) using representative sets

Bodlaender 1989: k!2knO(1) using treewidth

Alon, Yuster, Zwick 1994: O((2e)k |E |) by color coding

Kneis, Mölle, Richter, Rossmanith 2006: 4knO(1) by color coding

Koutis 2008: 23/2knO(1) by group algebras

Williams 2009: 2knO(1) by group algebras

Björklund, Husfeldt, Kaski, Koivisto 2010: 1.66knO(1), undirected!

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 31 / 46

Page 97: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

k-Path problem

Problem

Input: Directed graph G = (V ,E ), k ∈ N.Question: Does G contain a simple path on k vertices?

History

NP-complete (why?)

no trivial FPT algorithm,

Monien 1985: k!nO(1) using representative sets

Bodlaender 1989: k!2knO(1) using treewidth

Alon, Yuster, Zwick 1994: O((2e)k |E |) by color coding

Kneis, Mölle, Richter, Rossmanith 2006: 4knO(1) by color coding

Koutis 2008: 23/2knO(1) by group algebras

Williams 2009: 2knO(1) by group algebras

Björklund, Husfeldt, Kaski, Koivisto 2010: 1.66knO(1), undirected!

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 31 / 46

Page 98: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

k-Path problem

Problem

Input: Directed graph G = (V ,E ), k ∈ N.Question: Does G contain a simple path on k vertices?

History

NP-complete (why?)

no trivial FPT algorithm,

Monien 1985: k!nO(1) using representative sets

Bodlaender 1989: k!2knO(1) using treewidth

Alon, Yuster, Zwick 1994: O((2e)k |E |) by color coding

Kneis, Mölle, Richter, Rossmanith 2006: 4knO(1) by color coding

Koutis 2008: 23/2knO(1) by group algebras

Williams 2009: 2knO(1) by group algebras

Björklund, Husfeldt, Kaski, Koivisto 2010: 1.66knO(1), undirected!

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 31 / 46

Page 99: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Algorithm in time O(nk · n)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 32 / 46

Page 100: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Naive approach: exhaustive search

O(nk) sequences of k vertices

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 33 / 46

Page 101: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Naive randomized algorithm: guess a solution

O(nk) sequences of k vertices

Guess a sequence. Success probability ≥ 1/nk . Small.

Repeat nk times. If always failed, report NO.

Analysis:

If no solution, the answer is correct.If there is a solution,

Pr [error] ≤(1− 1

nk

)nk

≤ e−1 < 12.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 34 / 46

Page 102: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Naive randomized algorithm: guess a solution

O(nk) sequences of k vertices

Guess a sequence. Success probability ≥ 1/nk . Small.Repeat nk times. If always failed, report NO.

Analysis:

If no solution, the answer is correct.If there is a solution,

Pr [error] ≤(1− 1

nk

)nk

≤ e−1 < 12.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 34 / 46

Page 103: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Naive randomized algorithm: guess a solution

O(nk) sequences of k vertices

Guess a sequence. Success probability ≥ 1/nk . Small.Repeat nk times. If always failed, report NO.

Analysis:

If no solution, the answer is correct.If there is a solution,

Pr [error] ≤(1− 1

nk

)nk

≤ e−1 < 12.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 34 / 46

Page 104: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Question

We have got so-called Monte-Carlo algorithm with one-sided error.

Question

Why are we happy with error probability 1/2?

Answer:

Probability ampli�cation

Repeat the algorithm 1000 times and answer YES if there was at leastone YES. Then,

Pr [error ] ≤ 1

21000

Note

Probability of hardware failure during execution of an algorithm seems tobe much bigger than 1

21000...

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 35 / 46

Page 105: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Question

We have got so-called Monte-Carlo algorithm with one-sided error.

Question

Why are we happy with error probability 1/2?

Answer:

Probability ampli�cation

Repeat the algorithm 1000 times and answer YES if there was at leastone YES. Then,

Pr [error ] ≤ 1

21000

Note

Probability of hardware failure during execution of an algorithm seems tobe much bigger than 1

21000...

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 35 / 46

Page 106: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

An algorithm in time O(k!|E |)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 36 / 46

Page 107: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Idea: guess a subset of sequences.

O(nk) sequences of k vertices

Guess a subset of k-sequences A such that

Probability that A contains a solution sequence is `large'.

We can e�ciently check if A contains a solution sequence.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 37 / 46

Page 108: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

When the problem can be solved e�ciently?

Assume G = (V ,E ) is a directed acyclic graph (DAG).

Then we can in linear time �nd G 's topological order, i.e. apermutation of vertices

v1, v2, . . . , vn

such that (vi , vj) ∈ E implies i < j .

Dynamic programming detecting a k-vertex path in DAG: time O(|E |)1: for i ← 1 to n do T [i ]← 12: for i ← 2 to n do

3: for each (vj , vi ) ∈ E do

4: T [i ]← max{T [i ],T [j ] + 1}5: {Invariant: T [i ] = maximum length of a path ending at vi}

6: if ∃i T [i ] = k return YES else return NO

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 38 / 46

Page 109: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Randomized algorithm in time O(k!|E |)Repeat k! times:

1 Sample a permutation of the vertices (v1, . . . , vn),

2 Get a DAG G ′ = (V , {(vi , vj) ∈ E : i < j}).3 if G ′ contains a k-path (check in O(|E |) time) return YES.

If no k-path was found, return NO.

Analysis:

If no solution, the answer is correct.

If there is a solution (u1, . . . , uk),

Pr [single try success] = Pr [u1, . . . , uk in this order in v1, . . . , vn] = 1k!

Pr [error] = Pr [k! single failures] ≤(1− 1

k!

)k!

≤ e−1 < 12.

Total running time O(k! · |E |).�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 39 / 46

Page 110: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Algorithm in time O(k!|E |)

O(nk) sequences of k vertices

Aπ = k-sequences which are subsequences of π.

Probability that Aπ contains a solution is ≥ 1/k! (`large' !).

We can e�ciently check if Aπ contains a solution sequence.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 40 / 46

Page 111: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Algorithm in time O((2e)k|E |)

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 41 / 46

Page 112: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Idea

We had to be very lucky to guess a permutation which allows for�nding a solution in poly-time.

But we can a�ord for O(ck) time for a constant c .

Perhaps then it su�ces to be less lucky?

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 42 / 46

Page 113: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

More constrained problem: Colorful k-Path

Input: G = (V ,E ), k ∈ N and c : V → {1, . . . , k} (`coloring')Question: Does G have a colorful k-path, i.e., path v1, . . . , vk suchthat c({v1, . . . , vk}) = {1, . . . , k}.

Dynamic programming in time O(2k |E |)1: for each v ∈ V do

2: for each S ∈ 2{1,...,k} do3: T [v , S ]← [S = {c(v)}].4: for each S ∈ 2{1,...,k} (in the order of nondecreasing cardinality) do5: for each (u, v) ∈ E do

6: T [v , S ]← T [v , S ] ∨ T [u,S \ {c(v)}]7: {Invariant: T [v , S ] = [∃|S |-path with colors of S ending at v ]}

8: return∨

v∈V T [v , {1, . . . , k}].

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 43 / 46

Page 114: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Time O∗((2e)k) by color coding [Alon, Yuster, Zwick '95]

Repeat ek times:

1 Sample a coloring c : V → {1, . . . , k},2 Check if G contains a colorful k-path in time O(2k |E |), and if it does,

return YES.

If no k-path was found, return NO.

Analysis:

If no solution, the answer is correct.

If there is a solution (u1, . . . , uk),

Pr [single try success] ≥ k!/kk = (ke )k/kk = 1ek

Pr [error] = Pr [ek single failures] ≤(1− 1

ek

)ek

≤ e−1 < 12.

Total running time O(ek · 2k · |E |) = O((2e)k · |E |).�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 44 / 46

Page 115: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Time O∗((2e)k) by color coding [Alon, Yuster, Zwick '95]

O(nk) sequences of k vertices

Ac k-sequences with vertices of all k colors

Probability that Ac contains a solution is ≥ 1/ek (`large' !).

We can check in time O(2k |E |) (su�ciently e�ciently) if Ac containsa solution sequence.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 45 / 46

Page 116: Parametrized Algorithms Part 1 - mimuw.edu.plkowalik/teach/algorytmika/fpt.pdf · Parametrized Algorithms Part 1 ukasz Kowalik and Marcin Pilipczuk Warsaw, Poland, 21.05.2018 ukasz

Color coding: take-home message

Color coding is a very useful and general technique.

Most often, it is used to control a disjointness constraint (in k-path:non-repeating of the vertices)

There are methods to derandomize color coding (by universal hashfunctions), typically at the expense of worse constants in the runningtime.

�ukasz Kowalik, Marcin Pilipczuk (UW) FPT 1 46 / 46