• Nenhum resultado encontrado

A parallel algorithm for finding spanning trees of graphs

N/A
N/A
Protected

Academic year: 2021

Share "A parallel algorithm for finding spanning trees of graphs"

Copied!
13
0
0

Texto

(1)

.

*RELATóRIO TÉCNICO*

~

A F'ARALLEL ALGORITHH FOR

FINDING SF'ANNING TREES

OF GRAF'HS .!" ~ NCE-i6/90 Junho/90

i

tJni'/(:::\-sidade Fede1-al do !:;:10 d Janel\-O

"Ltc:l('?;o de C;omPLlt.::4.r;:j'.o El,,t,-6n:LC:a 1.".J".' l 'J.: \".- 1:'ot."l --,,"' .,-'"';j.':)24

20001 .-I:::io de Janel\-O -RJ JRAC 1.L

.l:, ;:) .J.

EstE a\-tigo será PLlblicado o,-iginalmEnte no I URSS-BRAZIL

Seminal-on Int'ol-matics, Scientific ComPLlting and Applied Hathematics, qLle

I-Ealizal--se-á em Nova FI-ibLll-go/RJ, no pe,-íodo de .24 a 27 de jLllho

de 1990. "

I -'..3 UNIVERSIDADE FEDERAL .DO RIO DE JANEIRO

mJ'-;:1 N(JCLEO DE COMPUTACÃO ELETRÔNICA

-..J

.

(2)

t

A p ARALLEL ALGORI THM FOR FI NDI NG SP ANNI NG TREES OF GRAPHS

ABSTRACT

We describe a parallel algorihm for finding he conneced

componens of a graph. The algorihm consrucs a spanning

ree for each ot' is connect.,ed componens in O(log2n) t.,ime

wih O«n+m)/log n) processors and O(n+m) space. under a

CREW PRAM model. where n and m a.re t.,he number of' vert.,ices

and edges of' t.,he graph. respect.,ively.

UM ALGORI TMO p ARALELO p ARA DETERMI NAR ARVOREs GERADORAS DE GRAFOS

RESUMO

Descrevemos um algorit-mo paralelo para det-erminar os

component-es conexos de uma gra.fo. O algorit-mo const-roi uma

arvore geradora para cada um de seus component-es conexos em

2

t-empo O(log n) .com O«n+m)/log n) processadores e O(n+m)

espaco. sob um modelo CREW PRAM. onde n e m represent-am os

(3)

A PARALLEL ALGORITHM FOR FINDING SP ANNI NG TREES OF GRAPHS l

Jayme Luiz Szwarcier

Unlversidade Federal do Rio de Janeiro

Nucleo de Compuacao Eleronca / Insiuo de Maemaica

Caixa Posal 2324. Rio de Janeiro. RJ

CEP 20001 -Brasil

June 1990

ABSTRACT

We describe a parallel algorihm for finding he conneced

components of a graph. The algorihm cor,strucs a spanning

tree for ".ach of its conneced components in O(log2n) time

with O(n+m)/log n) processors and O(n+m) space. under a

CREW PRAM model. where n and m are the number of vertices

and edges of the graph. respectively.

RESUMO

Descrevemos um algorimo paralelo para deerminar os

componenes conexos de uma graf'o. O algoritmo consroi uma

arvore geradora para cada um de seus componentes conexos em

tempo O(logZn) , com O«n+m)/log n) processadores e O(n+m)

espacb, sob um modelo CREW PRAM, onde n e m representam os

numeros de verices e aresas do graf'o, respecivamene.

(4)
(5)

2. The Algorithm

G denotes an ndirected graph. iLh verLex seL V(G) and edge sel

E(G) .IV(G) I = n and IE(G) I = :1.. A spar;'"1.ine foreS"t of G is a

subgraph F c: G such Lhat V (F) = V (G) and each O! i Ls connected

ccmponenLs is a tree. If !'or every edge (v.) E E(G) .v and w lie

in the same tree of F Lhen F is compLete; if they lie in differenL

1

;"i ones then F is triviaL. A Lrlvia.l foresL is denoted by F rt>. Slarting from it we describe an algorithm to construct a complete

foresL.

Any :;panning forest F induces a labe ling f;V -> { 1. n}. as

follo s: f(v) = f( ) iff v and w belon,J Lo a same Lree of I:'. .A.n

edge (v.w) E E(G) is active when f'(v) f(w). In lhis case.

letting f(v) < f(w). (v.w) i=:: an edge of type (O.f(.,.r)) and

(l.f(w»). An active vert.-ex is one incident wiLh an active edge.

Denote by n. (G) the number of such vertices of G. A transverS"aL H

of F having type p. Opl. is a subJraph of G such LhaL

(i) all edges of G are active. and

(ii) each v E V(G) is incidenL !.n H wiLh aL most c:"'le edge of

type (p.f(v).

Figure 1 illustraLes the t o Lypes of transversals.

The applicaLion of Lransversals in lhe process of determining a

complE-e spanning forest of G is based on the f"ollowing theorem.

Theorem. 1: Let G be a graph. F a spanni ng forest, ot' i L and H a

Lransversal of F. Then F V H is a spanning foresL.

, Proof: Assume f"irst LhaL H is cf' Lype O. Since F is a spanning

subgraph of G. so is F U H. We have Lhen to show that F U H has no

cycles. Suppose this is not true. and let C be Lhe cycle of F u H

I

-,1"" of Lhe form v. v. v. q > 2. LeL F. = F u C and H. = H u C.

""'('i\:- 1 q j.

,t; ""' WithouL loss of"

g

eneraliLy. let v be a verLex of leasL label in

1

,"'

"':.,

:,,"', C. Since F is a forest. C must. cont.ain an edge of H incide!)t. it.h each disti!)ct. label ot' C. Therefore. again wit.hout. loss of

,. -2

(6)
(7)
(8)

-edge of t,ype (O.f(v )) and since H does not, conlain any ot,her edge j.

of such lype. it, follows lhal H u { (v. v) } is also a lype O

j. 2

transversal. a contradict,ion. A similar argumenl proves that

I = {v v} U (V(G)-V:H)) is still an independent, set. NoW".

j. q

I I I = q + n I V (H) I. Si nce I E (H) I = I V (H) I q. i l follows

III = n -IE(H) I. If IE(H) I < n/2 then III n/2. Since G has no

isolaled verlices and I is an independenl sel. each W" E I must, be

I.

adjacenl lo a vert,ex W" e: I. Since H is maximum and of lype O. it J

follows f(w) > f(W"). Lel H. be t,he subgraph defined by selecting

1. J

one such (w.w) edge. for each w E I. Then H. is a lype 1

I. J I.

transversal of Frt> having II I > IE(H) I edges. a cont,radict,ion.

Therefore IE(H) I n/2.

o

Finding a maximum transversal is simple. Const,ruc'- a maximum

transversal H of each t,ype. 0 anà 1. and t,hen choose lhe largest

of t,hem. To obtain H. for lin. select, if possible as a

represenlat,ive of v. anyedge (v.v) such lhat f(v) < f(v) if

1. 1. J 1. J

H is of t,ype 0. ar f (v) > f (v .) ot,herwise.

I. J

.

The condensatton G (F) is lhe graph oblained from G by

idenlifying all verlices which lii& in a sar'e tree of F. It, follows

lhat, i f H i s a lransversal of some spanni ng forest, f. of G t,hen i t, .

is also a transversal of the lrivial forest, of G (F). We can now

formulale t,he algorit,hm.

Lel G be a given graph. In t,he tntttal. sta8e deIine F := Ftt>. In

the 8eneral. stae if n. (G) = 0 t,hE algorilhm t,ermin').t.es (F is a

complele foresl of G). Olberwise. find a maximum lransversal H of

.

the emply foresl of G. sel F : = F U H. G : = G (H) ard rep":?al lhe

general st,age.

" o

Theorem 2 asures lhal lhe number of it,eralions of lhe general

stage is al mosl 1 + Llog2(n-l)J.

" -5

(9)
(10)

-o

° 1

Next. for ql construct two vectors s and s :

1. if A (v) .õI! t:t> a I. sq(v) = I. O, otherwise. .. " f or 1<.< -l.-n. C o( ) 1 .,o 1

ompute E S v and E s (v). Defl.ne q := 0 l.f E s ? E s .and

I. I.

q := 1 otherwise. That is, the maximum transversal is of type q.

Finally. construct h as follows. For each v, 1in. if Aq(v) = <t>

I. o I.

then v has no representative and h(v) := 0; otherwise set

I. I.

h(v) := g(v) and r(v) := v, where v is the vertex of the

I. J I. J J

f i r s t node i n A ( v) . o \.

Using optimal list ranking. this step can be implemented in

O(log2n) time with O(n+m)/log n) processors. considering all

iterations of the general sage.

b. Com.put.in F := F U H:

:n thi3 step we identify all vertices of G belonging to a same

tree of H and assign them a coon label. We find a linear

ordering (say. preorder) on the vertices of the trees of H and use

it to guide the incorporation of H in T. The operations involved

are tr.e fcllowing.

First, perform the actual unic of the forests. Simply. for

lin. if h(v) .õI! ) then incluàe r (v.) in the adjacency list

I. I.

A (v) . F I.

Next. compute a preorder trave...sal of the trees of H. For this

operation. we are requ.i .-ed to construct the adjacency lists AH (Vi.)

of H. wi th each e,ige (v. .v) represented twi ce: v E A (v) and

I. J I. H J

V E A (v). To obtain the required structure. define a list L

J H I.

having 2. IE(H) I r:.)(;.es. as follows. Each v such th.at h(v.) .õI! 0

I. I.

contributes with two nr:),es to L. namely those correspondíng to the

edge (v. .h(v) ) E E(,-I) .Tre lists are formed after sorting L.

I. I.

(11)

-The act,ual preorder t...raversal is t,o be given bya vect,or p, in

t,he following maf)ner: for lif), if v e V(:-I) t,hef) p(v) := O;

I. I.

ot,herwise p(./) cont,ains t...he preorder successor of v in H. All

I. I.

.t,rees of H a,e dealt, wit,h if) parallel.

.c Now we proceed t,o updat...e t...he labels The idea is t,o choose a.

,;

t5 represent,at,i ve 1 abel of each t,ree of H (say, t...he 1 abel of i t,s root

.if) t,he preorder traversal) and assigf) it, t,o t,he labels of all

vert,ices of t,he t,ree. First" comput,e a vect...or root. such that... if

p(v) = 0 t...hen root(v) := 0; otherwise assigf) t,o root...(v) the

I. I. I.

root label of the tree of H which cof)t,ains v. Finally, for each

1.

vertex v such t...hat root...(v) 0. set f(v) : = f(root(v).

1. 1. 1. 1.

UsJ.f)g ar.propriat,e list... r; f)king. Euler t...our Of) t...r:es af)d sort...ir:g.

we caf) implement t,his step if) O(log2n) t,ime with O(f)/log n)

processors, overall. Observe that... the sum of t...he sizes o he lis

L. over all iteratiof)s of the general stage. is at n-ost... 2(n-l).

Therefore. the overall number of operat...ions requirej for sort...if)g

all list...s L is O(f) log f)). This agrees wit...h t,he above bouf)ds, A

similar argument... applies . t...o t...he comput...at...ion of vect...or root

c. Com.pu:ttn.e- G := G ("H.):

In t,his st...ep. we link t...oget...her t...he adjacef)cy list...s of t,he

vertices of G which f)OW. belong t...o a same t...ree of T. They

correspof)d t...o t...hose havirg a common label. The idea is t...o perform

t...his operat...ion guided by t...he preorder t...raversal of H. given by p.

-For lSin, it p(v) = v:! O t..her"\ we i:'lC.orporc..i:..e A (v) ir"1

1. J o J

.

ii A (v) , by makif)g t...he last... node of A (v) to point.. t,o t,he first.. of

o 1. o 1.

j' A (v) , af)d redefining A (v) : = t/>.

j a J a J

Next we update t...he values of g(v) as follows. For lin. if J

A (v) t/> t...hen examine each node v. E A (v) .If root... (v,) 0 set

a 1. J a 1. J

9 (v) : = root... (v.) .

J J

.,

(12)

-Firlally, comput,e t,he rlew value of rI' (G).

Thi:.;; st,ep can be implemerlt,ed irl overall t,ime O(log2r1) usirlg

O«(rI+m)/log rI) processors, agairl by opt,imal list rankirlg. Hence

these are t:1e boUnds for the entire algori L.hm.

4. Con(.:lusions

We have describec a parallel algorithm for findirlg a spal'1l'1irlg

tree of each COl'1nected COmponent of a graph, together with arl

implemerlt,at,iol'1 of complexity O(10g2n) t,lme it,h O«n+m)/log l'1)

proCeSSOrS and O(l'1+m) space, under a CREW PRAM model. Clearly, the

corlnected COmpol'1ent,S o!' the graph are obtained as a by-product,

of the spanrling trees.

"

(13)

-REFERENCES

" 1. M. Ajt.,ai. J. Komlos and E. Szemeredi. Sort.,ing ir'l c log

-Farallel Steps. Com.btnatortca 3 (1983) .pp. 1-19. "

2. B. Awebuch and Y. Shiloach. New Connectivity and MSF Algorithms for Shuffle Exchange Network and PRAM. IEEE Trans. on Computers C-:?6 (1987) .pp. 1258-1263.

3. R. Cole and U. Vishkin. Approximate and Exact Parallel

Scheduling with Applications to List. Tree and Graph Problems. Proc. 27th Ann'Ual. IEEE S:ym.p. on Fo'Undattons of Com.p. Sct. . 1986. pp. 478-491.

4. D. Eppstein ,;.,nd Z. Galil. Parallel Algorithmic Techniques for Comt:.-inatorial Computation. Ann. Rev. Comp. Sct. 1988. pp. 233-28::;.

5. D. S. Hirshberg. A. K. Chandra and D. V. Sarwate. Comput.ing Connected Compor-ents on Parall el Computers. CACH 22 (1979) .pp. 461 -,;:64.

6. R. M. Karp and V. Fa,-nach;lndran. Paral. e Aé'ort thms for S'"'.ared ,tem.or:y Hachtnes. Fep. UCB/CSD 38/408. Computer Sc. Div. . University o.f Cali.forni.a. 3erkeley. CA. 1988.

,

7. Y. Shiloach and U. Vishkif") An O(log n) Parallel Connectivity Algorithm. J. Al.ortthm.s 3 (1982) .pp. 57-67.

..

8. R. E. Tarjan and U. Vish!<in. An E.fficient Pa. allel Biconnectivity Algorithm. SIAl'1 J. Com.p 14 (1985) .pp. 862-874.

,.

Referências

Documentos relacionados

In this algorithm there is a single population (as in sequential GA) but the fitness evaluation and/or application of genetic operators are distributed among

In order to compare both algorithms, for each matrix m i , it was selected the number of threads t j that reached the best time reordering for... the

Tendo como referência o fragmento de texto acima e aspectos a ele relacionados, julgue os itens subsequentes. 93 Infere-se do texto que a população de menor renda ficará

Nomeado pelo Juiz para realização da perícia, deve o Perito analisar a matéria a ser periciada, bem como as partes que compõem o processo e proceder com as verificações se de fato

Dispõe sobre os conceitos de trabalho forçado, jornada exaustiva e condições análogas à de escravo para fins de concessão de seguro- desemprego ao trabalhador que vier a ser

A general algorithm for these applications, using the algorithm in this paper, is to generate spanning trees in order of increasing cost and check at each generation whether

Já a empresa Agrícola da Ilha especializada na produção de Hemerocallis, vem buscando a cada dia a qualidade de seus produtos, e buscando novas fontes de renda, como

The technique consists of the following: a spreading model defined in the space of small sets of genes studied and centered in each feature vector considered; the designing of