• Aucun résultat trouvé

The Smallest Block Containing a Given Subset

Dans le document This page intentionally left blank (Page 117-121)

Further Low-Level Algorithms

5.5. Blocks of Imprimitivity

5.5.2. The Smallest Block Containing a Given Subset

In a number of applications, we need to construct the block system with the smallest possible block sizes for some transitiveG= S ≤Sym(), = [1,n], satisfying the property that points of a given subsetbelong to the same block. The algorithm in Section 5.5.1 can be modified to do that, but we leave the details as an exercise (cf. Exercise 5.8). In this section we describe a faster method from [Atkinson et al., 1984].

Computation of the Smallest Block Containing

During the algorithm, we maintain a partitionof. Initially,consists of and|| − ||sets of size 1, the latter ones containing the elements of\.

Later we merge sets of, butalways satisfies the property that if two points ofbelong to the same set inthen they must belong to the same block in. Ifα, βbelong to the same set A inthen, for allsS, the points αs, βsmust belong to the same set. Hence ifαs andβsbelong to different sets A1,A2for someα, βandsSthen we delete A1andA2from,

and add the setA1A2to. The algorithm terminates when for allsSand Athere existsBsuch thatAs =B. At termination,consists of the blocks of the desired block system.

The efficiency of the algorithm depends on how quickly we can decide which set of apoint αs belongs to, and then how quickly we can perform the necessary merges of sets in.

We store the sets inin aUnion-Find data structure. Each setAis stored in arooted treeTA. Each vertex ofTArepresents an element inA, and the root represents the entire set as well. A vertexv ofTAconsists of three cells. One of them contains the appropriate element of A, and the second one contains a pointer to the parent ofv. The pointer of the root points to itself. The content of the third cell is considered only ifv is the root ofTA, and in this case the third cell contains|A|. In an implementation, the entire data structure forcan be stored in two lists of lengthn. Forα, letv(α) denote the tree vertex representingα. In one of the lists, at position αwe store the element of represented by the second cell ofv(α), and in the other one at positionαwe store|A|ifv(α) happens to be the root ofTAfor some set A.

We perform two operations on the data structure. One of them isFind(α), which finds the setAto whichαbelongs. This amounts to following the path (determined by the second cells of vertices) from the vertexv(α) repre-sentingαuntil we reach the root ofTA. In addition, after eachFindoperation, we also perform acollapseof the appropriate tree: We go along the path from αto the root again and change the parent of each vertex to the (already known) root. The cost ofFind(α), with or without applying the collapse rule, is(l), wherelis the length of the path fromv(α) to the root inTA.

The second operation isUnion(A,B), which replaces the sets A,Bby their union. We make one of the roots ofTA,TB achild of the other, and we update its second cell as the pointer to the new root. We also update the third cell of the new root. It is beneficial to use theweighted union rule: If|A| ≥ |B|

then the new root is the root ofTA, and otherwise the new root is the root of TB. We consider the cost ofUnion(A,B) as constant, regardless of whether we apply the weighted union rule (i.e., we ignore the cost of the arithmetic operations necessary for updating the third cell).

Theorem 5.5.7. Given a transitive G = S ≤ Sym(), = [1,n], and , the smallest block of imprimitivity of G containingcan be computed using at most2|S|nFindoperations and less than nUnionoperations.

Proof. As indicated in the preceding paragraphs, we initialize a partitionof to consist ofand|| − ||sets of size 1. We pick an arbitrary elementδ

ofas root, and we storein atreeTof depth 1. The other sets A= {α}

are represented by a treeTAwith one vertex. We also maintain a listLof pairs of points from. This list contains the pairs{α, β} ⊆for which we want to check whetherαsandβsbelong to the same set of, forsS. We initialize Lto contain all pairs{δ, β}, forβ\{δ}.

We process the listLas follows: If{α, β}is the next element ofLto process then for eachsSwe computeαsandβs, and we useFind(αs) a ndFind(βs) to determine which sets AandBinthese points belong to. IfA = Bthen we performUnion(A,B) and add the pairA, ρB}toL, where ρA andρB

are the elements ofrepresented by the roots ofTAandTB, respectively. The algorithm terminates when all pairs inL are processed.

We claim that at terminationconsists of the sets in ablock system. Since it is clear from the definition of blocks that, at any moment during the execution of the algorithm, points belonging to the same setAinmust belong to the same block in any block system whereis asubset of ablock, our claim implies that, at termination,consists of blocks of minimal possible size.

Forα, let A1A2 · · · Am be the sets in containingα during the algorithm. At termination, the setAmis in. Moreover, let (ρ1, . . . , ρm) be the sequence of elements ofthat are represented by the roots ofTA1, . . . ,TAm. Fori∈[1,m−1], ifρi =ρi+1then the pair{ρi, ρi+1}occurs inL, sinceAi+1

is obtained as the union ofAi with some set in. Moreover, ifρ1 =α(i.e., α\{δ}) then the pair{α, ρ1}is inL. Therefore, at terminationαs belongs to the same set ofasρms, for allsS. Since any generator ofGmaps each element ofAmto the same set as it mapsρm, applying this argument for all sets ofat termination gives thatGpermutes the sets in.

Because initiallyconsists of|| − || +1 sets, we obviously perform at most|| − || ≤n−1Unionoperations. Initially|L| = || −1, and we add at most|| − ||pairs toL. Hence|L| ≤n−1 at termination. For each pair

inL, we perform 2|S|Findoperations.

Lett(m,n) denote the worst-case time requirement of at mostmFind opera-tions and at mostn−1Unionoperations. If we do not use the collapse rule then it is fairly easy to estimatet(m,n), regardless of whether the weighted union rule is used or not (cf. Exercise 5.9). However, if both the collapse and weighted union rules are used then the analysis becomes much harder. The asymptotic behavior oft(m,n) was determined in [Tarjan, 1975]. To state the result, we have to introduce the Ackerman function.

LetA:N×N→Nbe defined recursively as follows: For alli,x∈N, let A(0,x) :=2x,A(i,0) :=0, andA(i,1) :=2. Moreover, fori ≥1 a ndx≥2,

let

A(i,x) :=A(i−1,A(i,x−1)). (5.3) Using (5.3), it is easy to see by induction thatA(1,x)=2xandA(i,2)=4 for allx≥1 a ndi ≥0. Also,A(2,x+1)=A(1,A(2,x))=2A(2,x), and so

A(2,x)=22··

·2

(atower ofxtwos).

The functionA(2,x) already grows very fast, butA(3,x) is mind-boggling. We haveA(3,0)=0,A(3,1)=2,A(3,2)=4,A(3,3)=A(2,A(3,2))=2222= 65536, and

A(3,4)=A(2,A(3,3))=22··

·2

(atower of 65536 twos).

Fori ≥4, the functions A(i,x) are growing even faster. We just compute one more value:A(4,3)=A(3,A(4,2))=A(3,4).

For fixedm≥1, we define the inverse of A(m,n) a s A1(m,n) :=min{x| A(m,x) > logn}. If m ≥ 3 then, for all practical purposes and beyond, A−1(m,n)≤4. The main result of [Tarjan, 1975] is the following theorem.

Theorem 5.5.8. Let t(m,n)denote the worst-case time requirement of at most m Find operations and at most n−1 Union operations, and suppose that mn. If both the collapse rule and the weighted union rule are used then t(m,n)∈(m A−1(m,n)).

Corollary 5.5.9. Given a transitive G = S ≤Sym(), with|| =n, and , the smallest block of imprimitivity of G containingcan be computed in O(|S|n A1(2|S|n,n))time by a deterministic algorithm.

The method described in this section can be used to test the primitivity of G, by computing the smallest block containing{α, β}for some fixedα and all β\{α}. However, this multiplies the running time indicated in Corollary 5.5.9 by a factorn. There is a possible shortcut. If we already know that the smallest block containing{α, β1}isand at a subsequent computation we deduce that the smallest block containing{α, β2}must containβ1, then we can terminate that computation. This observation usually helps in practice, but the worst-case running time is quadratic inn.

Dans le document This page intentionally left blank (Page 117-121)