• Aucun résultat trouvé

Definition and Dynamic Programming

There are several equivalent definitions of treewidth. Here we follow the defini-tion of Robertson and Seymour [182]. A tree decomposidefini-tion of a graphGis a way of representingGas a tree-like structure. In this chapter we will see how the tree decompositions and path decompositions of graphs can be used as tools for exact algorithms.

Tree decomposition.Atree decompositionof a graphG= (V,E)is a pair({Xi|i∈ I},T = (I,F))with{Xi|i∈I}a collection of subsets ofV, calledbags, andT = (I,F)a tree, such that

(T1) For everyv∈V, there existsi∈Iwithv∈Xi. (T2) For every{v,w} ∈E, there existsi∈Iwithv,w∈Xi.

(T3) For everyv∈V, the setIv={i∈I |v∈Xi} forms a connected subgraph (subtree) ofT.

Thewidthof tree decomposition({Xi|i∈I},T= (I,F))equals maxi∈I|Xi| −1. The treewidthof a graphG, tw(G), is the minimum width of a tree decomposition ofG.

To distinguish the vertices of the decomposition treeT and the vertices of the graphG, we will refer to the vertices ofT as to nodes.

Exercise 5.1.Prove that the treewidth of a tree with at least two vertices is 1, and that the treewidth of a clique onn≥1 vertices isn−1.

Thepath decompositionof a graph is a tree decomposition with treeT being a path. A path decomposition is often denoted by listing the successive sets

F.V. Fomin, D. Kratsch,Exact Exponential Algorithms, Texts in Theoretical 77 Computer Science. An EATCS Series, DOI 10.1007/978-3-642-16533-7 5,

c Springer-Verlag Berlin Heidelberg 2010

Fig. 5.1 A graph with a tree and a path decomposition

(X1,X2, . . . ,Xr).

Then the widthof a path decomposition(X1,X2, . . . ,Xr)is max1≤i≤r|Xi| −1. The pathwidthof a graphG, denoted by pw(G), is the minimum width of a path decom-position ofG. Clearly for all graphsG, tw(G)≤pw(G).

The property of tree decompositions which is important for performing dynamic programming over tree decompositions is the following.

Exercise 5.2 (Treewidth separator).Let({Xi|i∈I},T = (I,F))be a tree decom-position of a graphGand leti,j,kbe nodes ofT such that jis on the path fromito k. Then vertex setXjseparatesXi\XjandXk\Xj, which means that for every pair of verticesu∈Xi\Xjandv∈Xk\Xj, every(u,v)-path inGcontains a vertex from Xj.

The ideas of dynamic programming on graphs of bounded pathwidth and treewidth are quite similar. However, for pathwidth the description of algorithms is signifi-cantly simpler. We start with algorithms on graphs of bounded pathwidth.

It is convenient to work with nice decompositions. A path decomposition (X1,X2, . . . ,Xr).

of a graphGisniceif|X1|=|Xr|=1, and for everyi∈ {1,2, . . . ,r−1}there is a vertex vof Gsuch that eitherXi+1=Xi∪ {v}, orXi+1=Xi\ {v}. Let us note that because of Property (T3) of tree decompositions, every vertex ofGbelongs to consecutive sets of bags, and thus the number of bags in a nice path decomposition is at most twice the number of vertices ofG. See Fig.5.2for an example of a nice path decomposition.

5.1 Definition and Dynamic Programming 79

Fig. 5.2 Nice path decomposition of the graph from Fig.5.1

Exercise 5.3.LetX be a given path decomposition of a graphGof widthk. Then Ghas a nice path decomposition of widthk, moreover such a decomposition can be constructed in linear time fromX.

We exemplify the way dynamic programming on graphs of bounded pathwidth works on the following NP-complete graph problem.

Maximum Cut. In the MAXIMUM CUT problem (Max-Cut), we are given an undirected graph G= (V,E). For subsets of vertices V1 andV2 of G we define CUT(V1,V2)as the number of edges betweenV1andV2, i.e. the number of edges having one endpoint inV1and one endpoint inV2. The task is to find a setX⊆V that maximizes the value of CUT(X,V\X).

Lemma 5.4.Let G= (V,E)be a graph on n vertices with a given path decomposi-tion of width at most k. Then theMAXIMUMCUTproblem on G is solvable in time O(2k·k·n).

Proof. By making use of Exercise5.3, we transform in linear time the given path decomposition into a nice path decomposition

P= (X1,X2, . . . ,Xr) ofGof widthk.

Fori∈ {1,2, . . . ,r}, we put

Vi=

i [

j=1

Xj.

ThusVr=V. For every possible partition ofXiinto sets(A,B)we want to compute the value ci(A,B), which is the maximum size of a cut in the graphG[Vi], where the maximum is taken over all cuts(A0,B0)such thatA⊆A0 andB⊆B0. In other words,ci(A,B)is the maximum number of edges in a cut inG[Vi]in a partition ofV respecting the partition(A,B). Then the maximum number of edges in a cut inGis

a ab b bc c ce

ced cd

cf cdf

ghi gh

g

fg cfg

gh h

max{cr(A,B):(A,B)is a partition ofXr}.

We use dynamic programming to computeci(A,B)for every partition(A,B)of Xi. The casei=1 is trivial, hereX1=vfor somev∈V, and there are only two parti-tions ofX1, namely({v},/0)and(/0,{v}). In both cases,c1({v},/0) =c1(/0,{v}) =0.

Fori>1, we consider two cases

—Xi=Xi−1∪ {v}, for somev∈V. By Exercise5.2, all neighbors ofvinVimust be inXi−1∩Xi(for everyu∈Vi−1\Xi−1, the setXi−1must separateuandv). Then for every partition(A,B)ofXi,

ci(A,B) =

(ci−1(A\ {v},B) +CU T({v},B), ifv∈A,

ci−1(A,B\ {v}) +CU T({v},A), ifv6∈A (5.1)

—Xi=Xi−1\ {v}, for somev∈V. In this case, for every partition(A,B)ofXi, we have that

ci(A,B) =max{ci−1(A∪ {v},B),ci−1(A,B∪ {v})}. (5.2) The computation of the values ci(A,B) in (5.1) and (5.2) can be done in time O(2|Xi||Xi|)and by making use of spaceO(2|Xi|). Thus the total running time is

O(

r i=1

2|Xi||Xi|) =O(2k·k·n).

u t As another example of an algorithm on graphs of bounded pathwidth, we show how to count the number of perfect matchings in a graph of bounded pathwidth.

Note that the problem COUNTINGPERFECTMATCHINGSis #P-complete.

Lemma 5.5.Let G= (V,E)be a graph on n vertices with a given path decomposi-tion of width at most k. Then the problemCOUNTINGPERFECTMATCHINGScan be solved in timeO(2k·k·n).

Proof. As in Lemma5.4, we construct a nice path decomposition P= (X1,X2, . . . ,Xr)

ofGof widthkand fori∈ {1,2, . . . ,r}, we put Vi=

i [

j=1

Xj.

For every partition (A,B)of Xi, we define mi(A,B)to be equal to the number of matchingsMinG[Vi]such that every vertex ofVi\Bis an endpoint of some edge of M, and none of the vertices ofBis an endpoint ofM. Let us note that the number of perfect matchings inGis equal tomr(Xr,/0).

5.2 Graphs of Maximum Degree 3 81