• Aucun résultat trouvé

3.1.1 Permutation Problems

In this subsection we discuss how to use dynamic programming across the subsets to solve different permutation problems. In all these problems one has to find an optimal permutation of the elements of the ground set. One of the typical examples is the TRAVELLINGSALESMANproblem (TSP), discussed in Chap.1, where one asks for a permutation minimizing the total cost of a tour. Most of the permutation problems on a ground set of sizencan be solved trivially in timeO(n!). In Chap.1, we showed how dynamic programming across the subsets for TSP results in an algorithm of running timeO(2n). For many other permutation problems, dynamic programming allows us to reduce the running time to O(cn), for some constant c>1.

Scheduling Problem. Let us consider a SCHEDULING problem in which we are given a set of jobs J1,J2, . . . ,Jn, execution timesτ12, . . . ,τn, and cost functions c1(t),c2(t), . . . ,cn(t). Every jobJi requires timeτi to be executed, and there is an associated costci(t)when finishing jobJi at timet. The jobs have to be executed on a single machine. We assume that the machine is to be in use constantly and that an executed job is not to be interrupted before its completion (i.e. non-preemptive scheduling). Under these assumptions the order of executing jobs, orschedule, can be represented by a permutationπof{1,2, . . . ,n}. Given such a schedule, the ter-mination time of jobJπ(i)is

tπ(i)=

i

j=1

τπ(j)

and the total cost associated with the schedule is

n

i=1

cπ(i)·tπ(i).

For a given input, the task is to find the minimum total cost taken over all possible schedules; we call this minimum costOPT.

For a subset of jobsS, we denote the time required to finish all jobs fromSbytS, i.e.

tS=

i∈S

τi.

LetOPT[S]be the minimum cost of executing all jobs ofSin the interval[0,tS].

In caseS={Ji}, we haveOPT[S] =cii). If|S|>1, then

OPT[S] =min{OPT[S\ {Ji}] +ci(tS)}:Ji∈S}. (3.1) To see this, if in some optimal scheduling ofSjobJiis the last executed job, then

3.1 Basic Examples 33 OPT[S] =OPT[S\ {Ji}] +ci(tS).

Taking the minimum over all choices ofJi, we arrive at (3.1).

NowOPTcan be computed by dynamic programming based on (3.1). The num-ber of steps isO(n2n)and we conclude with the following.

Theorem 3.1.The scheduling problem is solvable in timeO(n2n).

There is a natural way to establish an algorithm based on the recurrence achieved.

The corresponding algorithmcostis described in Fig.3.1.

Algorithmcost(J1,J2, . . . ,Jn,τ12, . . . ,τn,c1(t),c2(t), . . . ,cn(t)).

Input: A collection of jobsJ1,J2, . . . ,Jnwith execution timesτ12, . . . ,τn, and cost functions c1(t),c2(t), . . . ,cn(t).

Output: The minimum cost OPT of a schedule.

fori=1to ndo OPT[{Ji}] =cii) forj=2to ndo

forallS⊆ {1,2,3, . . .n}with|S|=jdo

OPT[S] =min{OPT[S\ {Ji}] +ci(tS):JiS}

returnOPT[{1,2, . . . ,n}]

Fig. 3.1 Algorithmcostfor the SCHEDULINGproblem

Exercise 3.2.Thecutwidthof a vertex orderingπ of a graphG= (V,E)is maxv∈V |{{w,x} ∈E:π(w)≤π(v)<π(x)}|.

The cutwidth of a graphG= (V,E)is the minimum cutwidth taken over all linear orderings of its vertices. Prove that the cutwidth of a graph on n vertices can be computed in timeO(2n).

Exercise 3.3.Design and analyse dynamic programming algorithms to compute the pathwidth of a graph. See Chap.5for the definitions of pathwidth.

Directed Feedback Arc Set.In the DIRECTEDFEEDBACKARCSETproblem we are given a directed graphG= (V,A). The task is to find a feedback arc set of minimum cardinality, i.e. a set of arcsF⊆Asuch that(V,A\F)is acyclic and|F|is as small as possible. HenceF⊆Ais a feedback arc set of the directed graphG= (V,A)if each directed cycle ofGcontains at least one arc ofF.

At first glance the problem does not look like a permutation problem. However it can be expressed in terms of permutations. Let us recall that atopological ordering of a directed graphG= (V,A)is an orderingπ:V→ {1,2, . . . ,|V|}(or permutation) of its vertices such that all arcs are directed from left to right. In other words, for any arc(u,v)∈A, we haveπ(u)<π(v).

Lemma 3.4.Let G= (V,A)be a directed graph, and let w:A→N+be a function assigning to each arc a non-negative integer weight. Let k≥0be an integer. There exists a set of arcs F ⊆A such that(V,A\F)is acyclic and∑a∈Fw(a)≤k, if and only if there is a linear orderingπof G, such that

(x,y)∈A,

π(x)>π(y)

w((x,y))≤k.

Proof. The proof of the lemma becomes trivial after we make the following obser-vation: A directed graph is acyclic if and only if it has a topological ordering.

Indeed, if a graph is acyclic, it contains a vertex of in-degree 0. We take this vertex as the first vertex in the ordering, remove it from the graph and proceed recursively. In the opposite direction, if a directed graph has a topological ordering, then it cannot contain a cycle, because in any ordering, at least one arc of the cycle

should go from right to left. ut

By making use of Lemma3.4, it is now easy to obtain a recurrence like (1.1) or (3.1) and to solve DIRECTEDFEEDBACKARCSETin timeO(nm2n).

Theorem 3.5.TheDIRECTEDFEEDBACKARCSETproblem can be solved in time O(nm2n), where n is the number of vertices and m is the number of arcs of the given weighted directed graph G.

Exercise 3.6.We leave the proof of Theorem3.5as an exercise for the reader.

Exercise 3.7.In the OPTIMALLINEAR ARRANGEMENTproblem, we are given a graphG= (V,E). The task is to find the minimum value of

{v,w}∈E

|π(v)−π(w)|,

where the minimum is taken over all linear orderingsπof the vertices ofG. Prove that OPTIMALLINEARARRANGEMENTis solvable in timeO(2n).

Hint: Restate the problem as a permutation problem by proving that for each linear orderingπofV,

{v,w}∈E

|π(v)−π(w)|=

v∈V

|{{x,y} ∈E : π(x)≤π(v)<π(w)}|.

3.1.2 Partition Problems

Graph Coloring.Ak-coloringcof an undirected graphG= (V,E)assigns a color to each vertex of the graph c:V → {1,2, . . . ,k} such that adjacent vertices have different colors. The smallestkfor whichGhas ak-coloring is called thechromatic numberofG, denoted byχ(G). A coloringcofGusingχ(G)colors is called an

3.1 Basic Examples 35 optimal coloring. In the COLORING problem we are given an undirected graph G= (V,E). The task is to compute the chromatic number ofG, or even to find an optimal coloring ofG.

The computation of the chromatic number of a graph is a typical partition prob-lem, and the trivial brute-force solution would be for every vertex to try every possi-ble color. The maximum chromatic number of ann-vertex graph is equal ton; thus such a trivial algorithm has running timeO(nn)which is roughly 2O(nlogn). Theorem 3.8.The chromatic number of an n-vertex graph can be computed in time O((1+√3

3)n) =O(2.4423n)by a dynamic programming algorithm.

Proof. For everyX ⊆V, we defineOPT[X] =χ(G[X]), the chromatic number of the subgraph ofGinduced byX. The algorithm computes the values ofOPT[X]by making use of dynamic programming. For every subsetXin the order of increasing cardinality the following recurrence is used:

OPT[/0] =0, and

OPT[X] =1+min{OPT[X\I]:Iis a maximal independent set ofG[X]}.

We claim thatχ(G) =OPT[V]. Indeed, everyk-coloring of a graphGis a parti-tion of the vertex set intokindependent sets (resp. color classes) and that we may always modify thek-coloring such that one independent set is maximal. Therefore an optimal coloring ofGis obtained by removing a maximal independent setIfrom Gand adding an optimal coloring ofG\I.

What is the running time of this algorithm? Letn=|V|. The algorithm runs on all subsets X ⊆V, and for every subset X, it runs on all its subsets I, which are maximal independent sets inG[X]. The number of such sets is at most 2|X|. Thus the number of steps of the algorithm is up to a polynomial factor at most

n

i=1

n i

·2i=3n. (3.2)

In (3.2) we do not take into account that the algorithm does not run on all subsets of a subsetX, but only on maximal independent sets ofG[X]. As we already know from Chap.1, the number of maximal independent sets in a graph ofivertices is at most 3i/3 and these sets can be enumerated in timeO(3i/3). Thus up to a polynomial factor, the running time of the algorithm can be bounded by

n

i=1

n i

·3i/3= (1+√3

3)n<2.4423n. (3.3) u t

The running time obtained in Theorem3.8can be improved toO(2n)by com-bining dynamic programming with inclusion-exclusion. We will come back to this in Chap.4.

Exercise 3.9.In the DOMATICNUMBERproblem we are given an undirected graph G= (V,E). The task is to compute the domatic number ofGwhich is the largest integer ksuch that there is a partition ofV into pairwise disjoint setsV1,V2, . . .Vk such thatV1∪V2∪ · · · ∪Vk=V and eachViis a dominating set ofG. Show how to compute the domatic number of ann-vertex graph in timeO(3n).