60
Exact Algorithms for Hard Problems An introduction

Exact Algorithms for Hard Problems An introduction

  • View
    225

  • Download
    5

Embed Size (px)

Citation preview

Page 1: Exact Algorithms for Hard Problems An introduction

Exact Algorithms for Hard Problems

An introduction

Page 2: Exact Algorithms for Hard Problems An introduction

Seminar2

This talk

• Intro• Exact algorithms • Fixed parameter algorithms

Page 3: Exact Algorithms for Hard Problems An introduction

Seminar3

Why?

• Practical problems often NP-hard• Must still be solved, so use slow exact algorithm• Question: how fast can we do it?• Here: analysis of worst case times• Parameterized algorithms: sometimes something is

small: answer, or parameter of input

Page 4: Exact Algorithms for Hard Problems An introduction

Seminar4

Exact algorithms

• Take an NP-hard problem, and find an algorithm that solves it exactly, as fast as possible

• Typical running time: O( cn) for some constant.• Try to get c as small as possible

Page 5: Exact Algorithms for Hard Problems An introduction

Seminar5

O*-notation

• O*: suppress factors polynomial in input size from O-notation

• O-notation: asympthotic• O(n3 2n) = O*(2n)• Note: O*(1.89286n) = O(1.8929n)

Page 6: Exact Algorithms for Hard Problems An introduction

Seminar6

History

• Research done in the 1960s• Field somewhat forgotten for several years after

discovery of NP-completeness theory• Popular research topic in 1990s en 2000s again• Recent new techniques: re-discovery of inclusion-

exclusion; measure and conquer

Page 7: Exact Algorithms for Hard Problems An introduction

Seminar7

Techniques

• Dynamic programming• Branch and Reduce• Measure and conquer analysis of branch and reduce• Inclusion-exclusion• Memorization• Preprocessing• Local search based• Treewidth• Faster algorithms for planar graphs, and generalizations

(subexponential algorithms)

Page 8: Exact Algorithms for Hard Problems An introduction

Seminar8

Dynamic programming

• Works for many problems• Not always fastest solutions, and use also exponential

memory• Examples:

– Partition into triangles: given a graph, can we partition the vertices into groups of 3, each forming a triangle?

• O*(2n)– L(2,1)-coloring: color the vertices with numbers {1, …,

k}, such that adjacent vertices have colors differ by 2, and vertices at distance 2 have colors differ by 1.

• O*(4n). Faster algorithms are known

Page 9: Exact Algorithms for Hard Problems An introduction

Seminar9

Branch and reduce

• Explained by Johan• Measure and conquer: better analysis

Page 10: Exact Algorithms for Hard Problems An introduction

Seminar10

Memorization

• Technique to speed up some algorithms, explained in separate lecture

Page 11: Exact Algorithms for Hard Problems An introduction

Seminar11

Treewidth

• Special type of dynamic programming• Also: branchwidth, pathwidth are similar and

sometimes faster

Page 12: Exact Algorithms for Hard Problems An introduction

Seminar12

Faster algorithms for planar graphs

• O*(csqrt(n)) or O*(csqrt(n)* log n)• Using treewidth/branchwidth dynamic

programming algorithms• Planar graphs have treewidth O( sqrt(n))• Generalizes to some other types of graphs:

bounded genus, missing minor

Page 13: Exact Algorithms for Hard Problems An introduction

Seminar13

Fixed Parameter Complexity

• Many problems have a parameter• Analysis what happens to problem when some

parameter is small

Page 14: Exact Algorithms for Hard Problems An introduction

Seminar14

Motivation

• In many applications, some number can be assumed to be small– Time of algorithm can be exponential in this

small number, but should be polynomial in usual size of problem

– Or something is fixed

Page 15: Exact Algorithms for Hard Problems An introduction

Seminar15

Parameterized problem

• Given: Graph G, integer k, …• Parameter: k• Question: Does G have a ??? of size at least (at

most) k?– Examples: vertex cover, independent set,

coloring, …

Page 16: Exact Algorithms for Hard Problems An introduction

Seminar16

Examples of parameterized problems

(1)Graph Coloring

Given: Graph G, integer k

Parameter: k

Question: Is there a vertex coloring of G with k colors? (I.e., c: V {1, 2, …, k} with for all {v,w} E: c(v) c(w)?)

• NP-complete, even when k=3.

Page 17: Exact Algorithms for Hard Problems An introduction

Seminar17

Clique

• Subset W of the vertices in a graph, such that each pair has an edge

Page 18: Exact Algorithms for Hard Problems An introduction

Seminar18

Examples of parameterized problems

(2)Clique

Given: Graph G, integer k

Parameter: k

Question: Is there a clique in G of size at least k?• Solvable in O(nk) time with simple algorithm.

Complicated algorithm gives O(n2k/3). Seems to require (nf(k)) time…

Page 19: Exact Algorithms for Hard Problems An introduction

Seminar19

Vertex cover

• Set of vertices W V with for all {x,y} E: x W or y W.

• Vertex Cover problem:– Given G, find vertex cover of minimum size

Page 20: Exact Algorithms for Hard Problems An introduction

Seminar20

Examples of parameterized problems

(3)Vertex cover

Given: Graph G, integer k

Parameter: k

Question: Is there a vertex cover of G of size at most k?

• Solvable in O(2k (n+m)) time

Page 21: Exact Algorithms for Hard Problems An introduction

Seminar21

Three types of complexity

• When the parameter is fixed– Still NP-complete (k-coloring, take k=3)– O(f(k) nc)– O(nf(k))

Page 22: Exact Algorithms for Hard Problems An introduction

Seminar22

Fixed parameter complexity theory

• To distinguish between behavior:O( f(k) * nc)( nf(k))

• Proposed by Downey and Fellows.

Page 23: Exact Algorithms for Hard Problems An introduction

Seminar23

Parameterized problems

• Instances of the form (x,k)– I.e., we have a second parameter

• Decision problem (subset of {0,1}* x N )

Page 24: Exact Algorithms for Hard Problems An introduction

Seminar24

Fixed parameter tractable problems

• FPT is the class of problems with an algorithm that solves instances of the form (x,k) in time p(|x|)*f(k), for polynomial p and some function f.

Page 25: Exact Algorithms for Hard Problems An introduction

Seminar25

Hard problems

• Complexity classes– W[1] W[2] … W[i] … W[P]– Defined in terms of Boolean circuits– Problems hard for W[1] or larger class are

assumed not to be in FPT• Compare with P / NP

Page 26: Exact Algorithms for Hard Problems An introduction

Seminar26

Examples of hard problems

• Clique and Independent Set are W[1]-complete

• Dominating Set is W[2]-complete

• Version of Satisfiability is W[1]-complete

– Given: set of clauses, k

– Parameter: k

– Question: can we set (at most) k variables to true, and al others to false, and make all clauses true?

Page 27: Exact Algorithms for Hard Problems An introduction

Seminar27

So what is parameterized complexity about?

• Given a parameterized problem• Establish that it is in FPT

– And then design an algorithm that is as fast as possible• Or show that it is hard for W[1] or “higher”

– Try to find a polynomial time algorithm for fixed parameter

• Or even show that it is NP-complete for fixed parameters– Solve it with different techniques (exact or

approximation)

Page 28: Exact Algorithms for Hard Problems An introduction

Seminar28

FPT techniques

• Branching algorithms– Bounded search trees– Greedy localization– Color coding

• Kernelisation (local rules, global rules)• Induction

– Iterative compression– Extremal method

• Win/Win– Well quasi ordering– Structures (e.g., treewidth)

FollowingSloper/Telle

taxonomy

FollowingSloper/Telle

taxonomy

Page 29: Exact Algorithms for Hard Problems An introduction

Seminar29

Branching

• More or less classic technique of search tree• Counting argument helps to keep size of search

tree small• At each step, we recursively create a number of

subproblems: answer is yes, if and only if at least one subproblem has yes as answer

Page 30: Exact Algorithms for Hard Problems An introduction

Seminar30

Vertex cover

• First example: vertex cover• Select an edge {v,w}. Note that a solution includes

v or it includes w• If we include v, we can ignore all edges incident to

v in subproblems

v w

Page 31: Exact Algorithms for Hard Problems An introduction

Seminar31

Branching algorithm for Vertex Cover

• Recursive procedure VC(Graph G, int k)

• VC(G=(V,E), k)

– If G has no edges, then return true– If k == 0, then return false– Select an edge {v,w} E

– Compute G’ = G [V – v] (remove v and incident edges)

– Compute G” = G [V – w] (remove w and incident edges)

– Return VC(G’,k – 1) or VC(G”,k – 1)

Page 32: Exact Algorithms for Hard Problems An introduction

Seminar32

Analysis of algorithm

• Correctness– Either v or w must belong to an optimal VC

• Time analysis– At most 2.2k recursive calls– Each recursive call costs O(n+m) time– O(2k (n+m)) time: FPT

Page 33: Exact Algorithms for Hard Problems An introduction

Seminar33

Color coding

• Interesting algorithmic technique to give fast FPT algorithms

• As example: • Long Path

– Given: Graph G=(V,E), integer k– Parameter: k– Question: is there a simple path in G with at

least k vertices?

Page 34: Exact Algorithms for Hard Problems An introduction

Seminar34

Problem on colored graphs

• Given: graph G=(V,E), for each vertex v a color in {1,2, … , k}

• Question: Is there a simple path in G with k vertices of different colors?

– Note: vertices with the same colors may be adjacent.

• Can be solved in O(2k (nm)) time using dynamic programming

• Used as subroutine…

Page 35: Exact Algorithms for Hard Problems An introduction

Seminar35

DP

• Tabulate:– (S,v): S is a set of colors, v a vertex, such that

there is a path using vertices with colors in S, and ending in v

– Using Dynamic Programming, we can tabulate all such pairs, and thus decide if the requested path exists

Page 36: Exact Algorithms for Hard Problems An introduction

Seminar36

A randomized variant

• For each vertex v, guess a color in {1, 2, …, k}

• Check if there is a path of length k with only vertices with different colors

• Note:

– If there is a path of length k, we find one with positive chance ( 2k /k!)

– We can do this check in O(2k nm) time

– Repeat the check many times to get good probability for finding the path

Page 37: Exact Algorithms for Hard Problems An introduction

Seminar37

Derandomisation

• Instead of randomly selecting a coloring, check all colorings from a k-perfect family of hash functions

• A k-perfect family of hash functions on a set V is a collection H of functions V {1, …,k}, such that for each set W V, |W|=k, there exists an h H with h(W) = {1, …,k}

• Algorithm:– Generate a k-perfect family of hash functions – For each function in the set, check for the properly

colored path of length k

Page 38: Exact Algorithms for Hard Problems An introduction

Seminar38

Existence and generation of k-perfect families of hash

functions• Alon et al. (1995): collection with O(ck log n) functions

exist and can be deterministically generated

• Hence: O((2c)k nm log n) algorithm for Longest Path

– Generate all elements of k-perfect family of hash functions, and for each, solve the colored version with dynamic programming

• Refined techniques exist

Page 39: Exact Algorithms for Hard Problems An introduction

Seminar39

Remember Cook’s theorem

• NP-completeness helps to distinguish between decision problems for which we have a polynomial time algorithm, and those for which we expect no such algorithm exists

• NP-hard; NP-completeness; reductions• Cook’s theorem: `first’ NP-complete problem; used to

prove others to be NP-complete• Similar theory for parameterized problems by Downey and

Fellows

Page 40: Exact Algorithms for Hard Problems An introduction

Seminar40

Classes

• FPT W[1] W[2] W[3] … W[i] … W[P]

• Theoretical reasons to believe that hierarchy is strict

Page 41: Exact Algorithms for Hard Problems An introduction

Seminar41

Parameterized m-reduction

• Let L, L’ be parameterized problems.• A standard parameterized m-reduction transforms an input

(I,k) of L to an input (f(I,k), g(k)) of L’– L((I,k)) if and only if L’((f(I,k), g(k)) – f uses time p(|I|)* h(k) for a polynomial p, and some

function h• Note: time may be exponential or worse in k• Note: the parameter only depends on parameter, not on rest

of the input

Page 42: Exact Algorithms for Hard Problems An introduction

Seminar42

A Complete Problem

• Classes W[1], … are defined in terms of circuits (definition skipped here)

• Short Turing Machine Acceptance– Given: A non-deterministic Turing machine M, input x,

integer k– Parameter: k– Question: Does M accept x in a computation with at

most k steps?• Short Turing Machine Acceptance is W[1]-complete

(compare Cook)• Note: easily solvable in O(nk+c) time

Page 43: Exact Algorithms for Hard Problems An introduction

Seminar43

More complete problems for W[1]

• Weighted q-CNF Satisfiability– Given: Boolean formula in CNF, such that each

clause has at most q literals, integer k– Parameter: k– Question: Can we satisfy the formula by

making at most k literals true?• For each fixed q > 1, Weighted q-CNF

Satisfiability is complete for W[1].

Page 44: Exact Algorithms for Hard Problems An introduction

Seminar44

Hard problems

• Independent Set, Clique: W[1]-complete• Dominating Set: W[2]-complete• Longest Common Subsequence III: W[1]-

complete (complex reduction to Clique)– Given: set of k strings S1, …, Sk, integer m– Parameter: k, m– Question: is there a string S of length m that is a

subsequence of each string Si, 1 i k?

Page 45: Exact Algorithms for Hard Problems An introduction

Seminar45

Example of reduction

• Precedence constrained K-processor scheduling

– Instance: set of tasks T, each taking 1 unit of time, partial order < on tasks, deadline D, number of processors K

– Parameter: K

– Question: can we carry out the tasks on K processors, such that

• If task1 < task2, then task1 is carried out before task2

• At most one task per time step per processor

• All tasks finished at most at time D

Page 46: Exact Algorithms for Hard Problems An introduction

Seminar46

Transform from Dominating Set

• Let G=(V,E), k be instance of DS• Write n = |V|, c = n2, D = knc + 2n.• Take the following tasks and precedences:• Floor: D tasks in “series”:

1 2 3 … … … … D-2 D-1 D

Page 47: Exact Algorithms for Hard Problems An introduction

Seminar47

Floor gadgets

• For all j of the form j = n-1+ ac + bn (0 a < kn, 1 b n), take a task that must happen on time j (parallel to the jth floor vertex)

1 2 … j-1 j j+1 … … D-1 D

Page 48: Exact Algorithms for Hard Problems An introduction

Seminar48

Selector paths

• We take k paths of length D-n+1

• Each models a vertex from the dominating set

• To some vertices on the path, we also take parallel vertices:

– If {vi, vj} E, and i j, then place a vertex parallel to the n-1+ac+in-jth vertex for all a, 0 a < kn

1 … … … … … … … … D-n-1…

Page 49: Exact Algorithms for Hard Problems An introduction

Seminar49

Lemma and Theorem

• Lemma: we can schedule this set of tasks with deadline D and 2k processors, if and only if G has a dominating set of size at most k

• Theorem: Precedence constrained k-processor scheduling is W[2]-hard

• Note: size of instance must depend in polynomial way on size of G (and hence on k < |V|)

• It is allowed to use transformations where new parameter is exponential in old parameter

Page 50: Exact Algorithms for Hard Problems An introduction

Seminar50

Conclusions

• Fixed parameter proofs: method of showing that a problem probably has no FPT-algorithms

• Often complicated proof • But not always

Page 51: Exact Algorithms for Hard Problems An introduction

Seminar51

Kernelisation

• Preprocessing rules reduce starting instance to one of size f(k)– Should work in polynomial time

• Then use any algorithm to solve problem on kernel

• Time will be p(n) + g(f(k))

Page 52: Exact Algorithms for Hard Problems An introduction

Seminar52

Maximum Satisfiability

• Given: Boolean formula in conjunctive normal form; integer k

• Parameter: k• Question: Is there a truth assignment that satisfies

at least k clauses?• Denote: number of clauses: C

Page 53: Exact Algorithms for Hard Problems An introduction

Seminar53

Reducing the number of clauses

• If C 2k, then answer is YES– Look at arbitrary truth assignment, and truth

assignment where we flip each value– Each clause is satisfied in one of these two

assignment– So, one assignment satisfies at least half of all

clauses

Page 54: Exact Algorithms for Hard Problems An introduction

Seminar54

Bounding number of long clauses

• Long clause: has at least k literals• Short clause: has at most k-1 literals• Let L be number of long clauses• If L k: answer is YES

– Select in each long clause a literal, whose complement is not yet selected

– Set these all to true– All long clauses are satisfied

Page 55: Exact Algorithms for Hard Problems An introduction

Seminar55

Reducing to only short clauses

• If less than k long clauses

– Make new instance, with only the short clauses and k set to k-L

– There is a truth assignment that satisfies at least k-L short clauses, if and only if there is a truth assignment that satisfies at least k clauses

• =>: choose for each satisfied short clause a variable that makes the clause true. We may change all other variables, and can choose for each long clause another variable that makes it true

• <=: trivial

Page 56: Exact Algorithms for Hard Problems An introduction

Seminar56

An O(k2) kernel for Maximum Satisfiability

• If at least 2k clauses: return YES• If at least k long clauses: return YES• Else: remove all L long clauses, and set k=k-L

Page 57: Exact Algorithms for Hard Problems An introduction

Seminar57

Formal definition of kernelisation

• Let P be a parameterized problem. (Each input of the form (I,k).) A reduction to a problem kernel is an algorithm, that transforms A inputs of P to inputs of P, such that– P((I,k)), if and only if P(A(I,k)) for all (I,k)– If A(I,k) = (I’,k’), then k’ f(k), and |I’| g(k)

for some functions f, g– A uses time, polynomial in |I| and k

Page 58: Exact Algorithms for Hard Problems An introduction

Seminar58

Kernelisation implies FPT and vice versa

• If P has a reduction to a problem kernel, and is decidable, P is in FPT:– Use transformation– Solve remaining instance– Uses polynomial time, plus T(g(|I|)) time

• If P is in FPT, P has a (perhaps trivial) reduction to a problem kernel– Suppose we have an f(k) nc algorithm– If |I| > f(k), solve problem exactly: this is O(nc+1) time

• Formality: take small yes or no-instance afterwards– Otherwise, take original instance as kernel

Page 59: Exact Algorithms for Hard Problems An introduction

Seminar59

Iterative compression

• Idea: first find solution of size 1, then solution of size 2, etc. and use previous solution to find (if existing) the next one

Page 60: Exact Algorithms for Hard Problems An introduction

Seminar60

Conclusions

• Several techniques, will be discussed separately during course