• Aucun résultat trouvé

Computing the prefix of an automaton

N/A
N/A
Protected

Academic year: 2021

Partager "Computing the prefix of an automaton"

Copied!
14
0
0

Texte intégral

(1)

HAL Id: hal-00619217

https://hal-upec-upem.archives-ouvertes.fr/hal-00619217

Submitted on 5 Sep 2011

HAL is a multi-disciplinary open access

archive for the deposit and dissemination of

sci-entific research documents, whether they are

pub-lished or not. The documents may come from

teaching and research institutions in France or

L’archive ouverte pluridisciplinaire HAL, est

destinée au dépôt et à la diffusion de documents

scientifiques de niveau recherche, publiés ou non,

émanant des établissements d’enseignement et de

recherche français ou étrangers, des laboratoires

Computing the prefix of an automaton

Marie-Pierre Béal, Olivier Carton

To cite this version:

Marie-Pierre Béal, Olivier Carton. Computing the prefix of an automaton. Informatique Théorique

et Applications, 2000, 34 (6), pp.503-514. �hal-00619217�

(2)

Marie-Pierre B

eal InstitutGaspardMonge

 UniversitedeMarne-la-Vallee

Olivier Carton InstitutGaspardMonge  UniversitedeMarne-la-Vallee

Mar h7, 2001

Abstra t

We present analgorithm for omputingthe pre x of anautomaton. Automata onsidered are non-deterministi , labelledonwords, and an have "-transitions. The pre x automaton of an automaton A has the following hara teristi properties. It has the same graph as A. Ea h a eptingpathhasthe samelabelas inA. Forea hstateq,thelongest ommon pre x of the labels of all paths going from q to an initial or nalstate isempty. The interestofthe omputationofthe pre xofan automaton is that it is the rst step of the minimization of sequential transdu ers.

Thealgorithmthatwedes ribehasthesameworst asetime omplex-ityasanotheralgorithmduetoMohributouralgorithmallowsautomata thathaveemptylabelled y les. IfwedenotebyP(q)thelongest ommon pre xoflabelsofpathsgoingfromqtoaninitialor nalstate,itoperates intimeO((P+1)jEj)whereP isthemaximallengthofallP(q).

1 Introdu tion

Transdu ers are nite state ma hines whose transitions or edges are labelled bya pairmade of an input word and anoutput word. Theyare widely used inpra ti etomodelvariousthingslikelexi alanalyzersinlanguagepro essing [14℄,operationsinnumerationsystems[11℄oralsoen odingorde odings hemes for hannels[2℄. Asatransdu erhasinputandoutputlabels,andevenifthese labelsareletters,thereisingeneralnominimalequivalentobje tlikeforsimple nitestateautomata. Itisveryoftenrequiredthatthetransdu erhaslettersas inputlabelsandhasmoreoveradeterministi inputautomaton. Itisthen alled sequential. Usedasanen oder,thismeansthattheoutput odewordisobtained sequentially from the input data. Transdu ers whi h are not sequential, but whi hrealizesequentialfun tions, anbe rstdeterminized(seeforinstan e[4℄



InstitutGaspard Monge, Universitede Marne-la-Vallee, 5 boulevard Des artes, 77454 Marne-la-ValleeCedex2,Fran e. http://www-igm.univ-mlv.fr/~fbeal, artong

(3)

sequentialtransdu er,eveniftheoutputlabelsarevariablelengthwords. A hara terizationofminimalsequentialtransdu erswas rstgivenin[7℄. A pro eduretoprodu eaminimalsequentialtransdu eristhereindi ated. Itisin parti ularshownin[7℄thattheminimalsequentialtransdu erisobtainedintwo steps. The rstoneis the omputation ofthe pre xautomatonof theoutput automatonofthetransdu er. These ondstepisa lassi alminimizationofthe transdu erobtainedattheendofthe rststep,seenasanordinary nitestate automaton. The pre x of an automaton anbeinterpretedas an automaton with the sameunderlying graph, same behaviour but produ es its output as soonaspossible. Itsname omesfromthefa tthatforanystateq,thelongest ommonpre xP(q)oflabelsofpathsgoingfromqtoaninitialor nalstateis empty.

The rstalgorithmof omputationofthepre xofanautomatonappearsin [12℄and [13℄. The onstru tionis there alled aquasi-determinization. It has beennoti edbyMohrithatthe rststepoftheminimizationofsequential trans-du ersisindependentfromthenotionoftransdu ers. Thequasi-determinization isanalgorithmthatworkson nitestateautomata.Itkeepsthegraphofan au-tomatonand hangesonlythelabelsoftheedges. Roughlyspeaking,itpushes thelabelsoftheedgesfromthe nalstatestowardstheinitialstatesasmu has possible. ThealgorithmofMohrihasatime omplexityO((P+1)jEj),where EisthesetofedgesandP themaximumofthelengthsofP(q)forallstatesq. WeassumeherethatthenumberofstatesjQjislessthanthenumberofedges. Anotheralgorithm for omputingthe pre x ofautomaton hasbeenpresented in[5℄and[6℄. Theapproa hofthisalgorithmisreallydi erentfromours. Itis basedonthe onstru tionofthesuÆxtreeofatreeanditstime omplexityis O(jQj+jEj+SlogjAj),whereAisthealphabetandSisthesumofthelengths ofthe labelsof alledges ofthe automaton. Breslauer'salgorithm anthus be betterwhenthereisasmallnumberofedgesandMohri'salgorithmisbetterin theother ase. Inpra ti e,S anbeverylargeand P anbeverysmall. This makesthealgorithmsofMohriandoursalmostlinear. A omparisonofthetwo omplexitiesisgivenin[13℄.

Our algorith uses the same prin iple of pushing letters through states as Mohri'salgorithm does. Main restri tionto Mohri'salgorithm isthat itdoes notwork when theautomaton ontainsa y le ofempty label (the systemof equationsgiven in [13, Lemma 2p. 182℄ doesnotadmits aunique solutionin this ase). Somestepin Mohri'salgorithmrequiresthat theautomatonhasno emptylabelled y le. However,ifthestartingautomatondoesnothaveanysu h y le,thispropertyiskeptalongthepro ess. Thealgorithmistherefore orre t in this ase. This restri tionis notreally importantforappli ations sin e the transdu ersusedinpra ti e,likeinlanguagepro essing,havenoemptylabelled y lesinoutput.

In this paper, we present another algorithm of omputation of the pre x of an automaton whi h has the same worst ase time omplexity as Mohri's algorithm, O((P +1)jEj), and that works forall automata. The existen e ofemptylabelled y lesa ountsformostofthediÆ ultyin the oming

(4)

algo-algorithm onsistsinde reasingby1thevalueP atea hstep. Wepresentour algorithmforsequentialtransdu ersbutit anbedire tlyextendedtothe ase ofsubsequentialtransdu ers(see[7℄ or[4℄for thede nition ofasubsequential transdu er).

InSe tion2,were allsomebasi de nitionsfrom automatatheoryandwe de ne the pre xautomaton of an automaton. The omputation algorithm of thepre xofanautomatonispresentedinSe tion3. The omplexityisanalyzed in Se tion 4. In that se tionsomedata stru turesare des ribed whi h anbe usedtogettherighttime omplexityofthealgorithm.

2 Pre x of an automaton and appli ations

Inthesequel,A denotesa nite alphabet and" istheemptyword. Awordu isapre x of awordv ifthere is awordw su h that v =uw. The wordw is denoted by u

1

v. The longest ommon pre x of aset of wordsis the longest wordwhi hispre xofallwordsoftheset.

Anautomaton overA 

is omposedofasetQofstates,asetEQA 

Q ofedges andtwosetsI;F Qofinitial and nal states. An edgee=(p;u;q) frompto q isdenoted byp

u

!q, thewordubeingthelabeloftheedge. The automatonis niteifQandEare nite. Apath isapossiblyemptysequen eof onse utiveedges. Itslabelisthe on atenationofthelabelsofthe onse utive edges. Anautomatonis oftendenoted byA=(Q;E;I;F). An a epting path is a path from an initial state to a nal state. The languageor set of words re ognized(ora epted)byanautomatonisthesetoflabelsofa eptingpaths. Anautomatonisdeterministi ifitislabelledbylettersofa nitealphabet A, ifithasoneinitialstateandifforea hstatepandea h letterainA, thereis atmostoneedgep

a

!qforsomeq.

We now de ne thepre x automatonof a given automatonA. This pre x automatonhasthesamegraphasA, but the labelsof theedges are hanged. However the labels of the a epting paths remain un hanged and the pre x automaton re ognizes the same words. Furthermore, for any state q of the pre x automaton the longest ommon pre x of the labels of all paths going fromqtoaninitialor nalstateisempty.

Let A = (Q;E;I;F) be a nite non-deterministi automaton labelled by words. Weassumethattheautomatonistrim,that is,anystatebelongstoan a eptingpath. Forea hstateq,wedenotebyP

A

(q),orjust P(q),thelongest ommonpre xofthelabelsofallpathsgoingfromqtoaninitialor nalstate. RemarkthatP(q)="ifq isinitialor nal.

The pre x automaton of A is theautomaton A 0 =(Q;E 0 ;I;F) de ned as follows. E 0 =fq P(q) 1 uP(r) !rjq u !risanedgeofAg:

One may easily he k that if q u

(5)

onsistent.

NotethatapathlabelledbywfromqtorinAbe omesapathlabelledby P(q)

1

wP(r)from qto r in thepre xautomaton. If thispath isa epting,q isinitialandris nalandthusP(q)andP(r)arebothempty. Thenthelabel ofthe pathin the pre xautomaton isthesame asin A. The label ofa y le ofAis onjugatedtoitslabelinthepre xautomaton. Inparti ulartheempty labelled y lesofthepre xautomatonarethesameastheonesof A.

By onstru tionthe longest ommon pre xof thelabelsofall pathsgoing fromqtoaninitialor nalstateisemptyin thepre xautomaton.

Our de nition of the pre x automaton allows edges oming in an initial state. Inmost ases,there isnoneandforea hnon-initial stateq,P(q)is the longest ommonpre xofthelabelsofallpathsgoingfrom qtoa nalstate.

The wordsP(q) arethe longestwordssu h that P(q) =" ifq is initial or naland su hthat P(q)is apre xof uP(r) forany edgeq

u

!r. Indeed,if a fun tionP

0

mapsanystateqtoawordsu hthatthesetwo onditionsaremet, thenP

0

(q)isapre xofP(q)foranystateq.

1 2 3 4 ba " " a a a Figure1: An automatonA. 1 2 3 4 baa " " a "

Figure2: Thepre xautomatonofA.

Example1 ConsidertheautomatonA pi turedin Figure 1where theinitial state is 1 and the nal state is 4. The pre x automaton of A is pi tured in Figure2.

(6)

quentialandsubsequentialtransdu ers. Atransdu erisde ned asan automa-ton, ex eptthat the labels of theedges are pairs made of aninput wordand anoutputword. A transdu erlabelledin AB



is sequential ifitsinput au-tomaton is deterministi . It hasbeen proved [7℄, [8, p. 95℄, see also [12℄ and [13℄, that amongthe sequentialtransdu ers omputing agiven fun tion,there is aminimal one whi h an be obtainedfrom any sequential transdu er om-puting the fun tion. This minimization is performed in two steps. The rst step is the omputation of the pre x automatonof the output automaton of thetransdu er. These ond stepisaminimization oftheresultingtransdu er, onsideredasa niteautomaton.

Wereferto [12℄forexamplesofminimization ofsequentialtransdu ers.

3 Computation of the pre x of an automaton

Inthis se tion, we des ribean algorithmwhi h omputesthe pre xof an au-tomaton. The automaton A = (Q;E;I;T) is anon-deterministi automaton whoseedgesare labelledbywordsovera nitealphabet A. Thelabels anbe theemptywordand y leswithemptylabelsareallowed.

We rstdes ribetheprin ipleofthealgorithm. IfqisastateofA,were all that P(q) denotes the longest ommon pre x of the labels of all paths going fromq to aninitialor nal state. Wedenoteby p(q)the rst letterof P(q) if P(q)6=",and"ifP(q)=".

WedenotebyP A

themaximumofthelengthsofallP(q)forallstatesq. If P

A

>0, we onstru t from the automatonA=(Q;E;I;T) an automa-tonA

0

=(Q;E 0

;I;T)whoseedgesarede ned asfollows:

E 0 =fq p(q) 1 up(r) !rjq u !risanedgeofAg:

Itre ognizesthesamelanguageasAandsatis es P A

0 =P

A

1. Byiterating thispro ess,wegetthepre xautomaton.

We now explain the omputation of the automaton A 0

. We all "-edge any edge whose label is ". Let A

"

be the sub-automaton of A obtained by keepingonlythe"-edges. We rst omputethestrongly onne ted omponents ofA

"

. This anbeperformedbydepth- rstexplorationsofA "

[9℄. Thestrongly onne ted omponents are storedin anarray indexed by Q. Forea h state q wedenote by [q℄a statethat representsthe strongly onne ted omponent ofq. The alltoStrongly-Conne ted-Components(A

"

)inthepseudo ode belowwillrefertothispro edure that omputesthearray .

Note that allstatesq in asamestrongly onne ted omponentof A "

have sameP(q)andthus samep(q).

The onstru tionofA 0

isthen donewithtwodepth- rstexplorations, rst anexplorationofA

"

,se ond,anexplorationofA.

The rst exploration omputes p(q) for ea h state q of A "

. This symbol, either a letter or ", is stored in the ell letter[q℄ of an array letter. As p(q)

(7)

" omputeitonlyforthestates [q℄.

Atthebeginningofthe omputation,all ellsletter[q℄aresettothedefault value>whi h standsfor unde ned. Duringthe omputation, thesevaluesare hanged into symbolsof A[f"g. Let X be the set A[f";>g. Wede ne a partialorderontheset X asfollows. Forea ha2A,

"<a<>:

Notethatea hsubsetofX hasaninf inX su hthat,forallx2X,alla;b2A witha6=b,

inf(";x)="; inf(>;x)=x; inf(a;b)=":

Wealsoassumethatanarraylo al indexedbyQgives,forea h stateq, either " if q is nal or initial, orinf(S) where S is the set of letters that appear as the rst letter of a non-empty label of an edge going out of q. Note that if there is noedge with anon-empty labelgoing out ofq, lo al [q℄ is equalto >. The array lo al is initialized by the pro edure Init-Table and updated with thepro eduresUpdate-Table-Head andUpdate-Table-Tailthatweshall des ribelater.

Forea hstateqinQ,thevalueofletter[ [q℄℄is rstsettotheinf oflo al [r℄, forall statesr in thesamestrongly onne ted omponentof A

"

asq. This is donebythepro edureInit-Letter. Duringtheexplorationoftheautomaton A

"

, ifq hasasu essorr su h that letter[ [r℄℄ <letter[ [q℄℄, thenletter[ [q℄℄ is hangedininf(lo al [q℄;letter[ [q℄℄). We laimthatthe ellofindexqofthearray letter ontainsp(q)at theend ofthisexploration. Thisexplorationisdoneby thefun tionFind-Letter. Itreturnsabooleanwhi histrueifthereisatleast onestateqwithp(q)non-empty.

Wegivebelowapseudo odeforthepro eduresInit-Letter,Find-Letter andFind-Letter-Visit. Wefollowthedepth- rstsear hpresentationof[9℄.

Init-Letter(setofstatesQ) forea hstateq2Qdo

letter[ [q℄℄ > for ea hstateq2Qdo

letter[ [q℄℄ inf(lo al[q℄;letter[ [q℄℄)

Find-Letter(automatonA " =(Q;E " ;I;F)) bool false

forea hstateq2Qdo olor [q℄ white forea hstateq2Qdo

if olor [q℄=white then Find-Letter-Visit(A

" ;q) returnbool

(8)

" " olor [q℄ bla k

forea hedge(q;";r)do if olor [r℄=whitethen

Find-Letter-Visit(A "

;r) letter[ [q℄℄ inf(letter[ [q℄℄;letter[ [r℄℄) if letter[ [q℄℄6="then

bool true

Wenowprovethe orre tnessofouralgorithm.

Proposition2 Fun tion Find-Letter omputes p(q)for ea h stateq.

Proof. Forea hstateq,\letter[ [q℄℄p(q)"isaninvariantofthefun tion Find-Letter. Indeed,onehaslo al [r℄ p(q),forea hstater inthe samestrongly onne ted omponentasq. Thisimpliesthat\letter[ [q℄℄p(q)"isaninvariant of thefun tion Init-Letter(Q). Moreover,ifthere is an edge (q;";r) and if letter[ [r℄℄p(r), wegetletter[ [r℄℄p(r)p(q). Then\letter[ [q℄℄p(q)"is invariantduring Find-Letter-Visit(A

" ;q).

Wenowshowthatifthereisanedge(q;";r)betweentwostatesqandr,we haveletter[ [q℄℄letter[ [r℄℄attheendofFind-Letter(A

"

). Thisfa tistrivial ifqandrbelongto thesamestrongly onne ted omponentofA

"

. If not,the endoftheexplorationofstaterisbeforetheendoftheexplorationofq. Then theline 5of Find-Letter-Visit(A

"

;q)impliesthatletter[ [q℄℄letter[ [r℄℄. Let us assume there is a (possibly empty)path from q to a stater whi h hasanempty label and anedge going outof r labelledwith au, where uis a word. Then letter[ [q℄℄aat theend of Find-Letter-Visit(A

"

;q). Indeed, attheendofFind-Letter-Visit(A

"

;q),wehaveletter[ [r℄℄a,andthenalso letter[ [q℄℄letter[ [r℄℄a.

Letusassumethatp(q)isaletterain A. Thenthereisa(possiblyempty) pathfrom qto astaterwhi h hasanempty labeland anedgegoing outofr labelledwithau,where uisaword. Asa onsequen eletter[ [q℄℄aandthen letter[ [q℄℄=p(q). Letusnowassumethatp(q)istheemptyword. Thenthere iseithera(possiblyempty)pathfromq toastater whi h hasanemptylabel and an edge going outof r labelled with au, where u is aword, and there is a(possiblyempty)pathfrom qto astater

0

whi h hasanempty labelandan edgegoingoutofr

0

labelledwithbu,whereuisaword,withb6=a. Inthis ase letter[ [q℄℄inf(a;b) =", and thenletter[ [q℄℄ =p(q). Orthere is a(possibly empty) pathfrom q toastater whi h hasan empty labeland withr nal or initial. Againletter[ [q℄℄letter[ [r℄℄=". Finally,letter[ [q℄℄=p(q)forea hq. 

These onddepth- rstexplorationisanexplorationoftheautomatonA. It updatesthelabelsofAin ordertode reasethelengthofP(q)forea hstateq su hthatp(q)isnon-empty. Forea hedge(q;u;r),whereuisa niteword,the following two operationsare performed. The letter (orempty word)p( [r℄) is addedattheendofu. Thenthe rstletter(oremptyword)p( [q℄)isremoved

(9)

nonempty,thenp( [q℄)isthe rstletterof uandifu="thenp( [q℄)=p( [r℄) orp( [q℄)=". Theseoperations hangethelabelsoftheedgesoftheautomaton Aandthusalsothevaluesofthearraylo al . Lines3and5of Move-Letter-Visit hange the labels of the edge e in A. Sin e an edge with empty label an be ome an edge with a non-empty label and onversely, the edge of A

" are also updated there. The values of the array lo al are updated with two pro edures Update-Table-head and Update-Table-Tail des ribed later. The exploration is done during the run of pro edure Move-Letter whose pseudo odeisgivenbelow.

Move-Letter(automatonA=(Q;E;I;F)) forea hstateq2Qdo

olor [q℄ white forea hstateq2Qdo

if olor [q℄=white then Move-Letter-Visit(A;q)

Move-Letter-Visit(automatonA=(Q;E;I;F)),stateq) olor [q℄ bla k

forea hedgee=(q;u;r)whereuisa(possiblyempty)worddo appendletter[ [r℄℄ attheend ofthelabelofeinAandupdateA

" Update-Table-Tail(e;letter [ [r℄℄)

removeletter[ [q℄℄fromtheheadofthelabelofein AandupdateA " Update-Table-Head(e;letter [ [q℄℄)

if olor [r℄=whitethen

Move-Letter-Visit(A;r)

Proposition 3 Fun tion transforms the automaton A in an automaton A 0 whoseedges are:

E 0 =fq p(q) 1 up(r) !rjq u !r isanedgeof Ag:

Therefore, the fun tion Move-Letter hanges thelabelw ofany path fromq torintop(q)

1 wp(r).

Proof. Thisfollowsdire tlyfrom the onstru tion. 

Proposition 4 Fun tion Move-Letter transforms the automaton A in an automatonA

0

whi hhasthesamegraphasA,keepsthelabelsofa eptingpaths andsatis esP A 0 =P A 1.

Proof. Letw bethelabel ofapath from aninitial stateito a nal statet in A. Thelabelofthesamepathobtainedattheend of Move-Letter in A

0 is p(i)

1

wp(t)=w. Thusthelabelsofa eptingpathsareun hanged. Moreover, forea h stateq onehasP

A 0 (q)=p A (q) 1 P A (q). It followsthat P A 0 =P A 1 ifP A 1. 

(10)

mainpro edureofthealgorithm. Make-Prefix(automatonA=(Q;E;I;F)) Init-Table(A) Strongly-Conne ted-Components(A " ) repeat Init-Letter(Q) bool Find-Letter(A " ) if bool then Move-Letter(A) untilbool =false

The resultof the omputation of theautomaton Api tured in Figure 1is theautomaton pi tured in Figure 2. Theautomaton A is su h that P

A =". Notethatthisautomatonhasanemptylabelled y le.

Remark5 Thetwopro eduresFind-LetterandFind-Letter-Visit anbe performedonthedire ted a y li graphobtainedasthe quotientofA

" by the relationof beingin asamestrongly onne ted omponent. This graph anbe mu hsmallerthanA

"

itself. It anbe omputedbythepro edureStrongl y-Conne ted-Components.

Remark6 Byproposition3,thelabelofa y leis hangedintooneofits on-jugatebythefun tion Move-Letter. Therefore,thestrongly onne ted om-ponentsofA

"

areun hangedduringtheiterationoffun tionMake-Prefix.

4 Data stru tures and omplexity

Inordertoanalyzethe omplexityofouralgorithm,webrie ydis ussapossible implementationofstru turesrequiredinthe onstru tion.

A lassi alway forimplementingtheautomatonA isto use jQjadja en y liststhatrepresenttheedges. Wemayassumethatwehavetwoadja en ylists forea hstateq. The rstonerepresentstheedgesofemptylabelgoingoutof q,thatistheedgesthatalsobelongtoA

"

. These ondonerepresentstheedges ofnon-emptylabelgoingoutofq.

Inorderto ompute,forea hstateq,lo al (q)ina onstanttime,wemaintain anarrayL indexedbyQde nedasfollows:

 L[q℄ isthe list of pairs(a;n) with a2A;n >02N, su h that q hasat leastoneoutgoingedgelabelledbyawordwhose rstletterisaandsu h thatnisthepositivenumberofedgesgoingoutofqandwhose rstletter isa.

(11)

ontains". Thuslo al (q)is"ifL[q℄hasmorethanoneelementorifqisinitial or nal. ItistheletteraifL [q℄ ontainsexa tlyonepair(a;n)andqisneither initialnor nal. It is>otherwise.

Theoperationperformedinthelistsaretheinsertionofanewletter,thatis apair(a;1), thein rementationand de rementationof these ond omponent ofanelement, andthedeletion ofaletter,that isofapair(a;1). Weneedall theseoperationstobeperformedina onstanttime.

Weuseaknownte hniquewhi h allowsus togetthistime omplexity(see forexample[1℄exer ise2.12p. 71and[10℄exer ise\Implantationdefon tions partielles"1.14Chapter 1). This te hniqueisbasedontheuseofarrayofsize jQjjAj whi hisnotinitialized.

WeassumethatthelistsL[q℄aredoublylinkedandimplementedwith ur-sors. WedenotebyT anarrayofvariablesize. The ellsofT areusedtostore the elements of the listsL [q℄. Ea h ellhas several elds: a eld label whi h ontainstheletter,a eldnumber that ontainsthenumberofedgesgoingout ofqwhose rstletterislabel,a eldstate whi h ontainsthestateqsu hthat the ellbelongsto L[q℄,and nally elds next andprev that givetheindex of thenext(respe tivelyprevious)elementinthesamelist. The ellofindexqof thearrayListheindexinT ofthe rstelementofL[q℄,ifthislistisnon-empty. AnotherarrayU,indexedbyQA,givesforea hpair(q;a)theindexinT ofthe ellofL[q℄whoseletterisa,ifthisletterisinL[q℄. Thisarrayallowsus to a ess anelement of alist in a onstanttime. Theoperationsof insertion, deletionofanelementinalistarethendoneina onstanttime. Theoperations ofin rementationandde rementationofthe eldnumber ofthe ellofagiven labelin agivenlistarealsodonein a onstanttime. Indeed,to in rementthe eldnumber oftheletterainL[q℄, onein rementsthe eld number ofthe ell ofT indexed byU[q;a℄.

ThearrayT isinitiallyemptyanditssizeis0. ThesizeofT isin remented whenanew ellisneededinT. A ellthat orrespondstoanelementofalist thathasjustbeenremovedismarkedtobefree. Thustheexisten eofaletter a in L[q℄ is obtained by he king whether U[q;a℄ is an index i in [1;size(T)℄, whetherthe ellT[i℄isnotmarkedfree, andwhether the eldslabel and state arerespe tivelyequaltoaandq. Thisisperformedin a onstanttime.

All thelistsofsu essorsthat representtheedgesoftheautomatonAand A

"

, and the arrays lo al , L, T, U are updated when the label of an edge is hangedduringthepro ess. ThearraysLandlo alareinitializedbythe pro e-dureInit-Table. ThearraysL, T,U andlo alareupdatedbythepro edures Update-Table-Head andUpdate-Table-Tail.

Wegivebelowapseudo odeforthepro edure Init-Table.

Init-Table(automaton A=(Q;E;I;F)) forea hq2Qdo

L[q℄ theemptylist lo al [q℄ >

(12)

if aisnotin L [q℄then

insertthepair(a;1) inL[q℄

elsein rementthe eldnumber oftheletterain L[q℄ if L[q℄hasmorethanoneelementorifqisinitialor nalthen

lo al [q℄ "

elseif L[q℄ isnotemptythen

lo al [q℄ theuniqueletterofL [q℄

Wenowdes ribetheupdatingofthetables andlists. An updateisneeded assoonasthelabelofanedgeofAis hanged. Notethatthelabelsoftheedges oftheautomataAandA

"

are hangedina onstanttime. Indeed,alabelofan edgegoingoutofastateqthatbe omesemptyisremovedfromthelistofedges of non-empty labels going outof q, and addedinto the list of edges of empty labelsgoingoutofq(and onversely). Thisisperformedin a onstanttimein line3 andline 5of Move-Letter-Visit. Toupdate thearraysL, T, U and lo al ,wedistinguishthetwokindsofmodi ationofthelabelsoftheedges. A letter orthe empty word anbe added at the end of a label. The pro edure alled to update is in this ase the pro edure Update-table-Tail. A letter ortheemptyword anberemovedfromtheheadof thelabel. Thepro edure alledtoupdateis inthis asethepro edureUpdate-table-Head.

Pseudo odesforUpdate-table-TailandUpdate-table-Headaregiven below.

Update-table-Tail(edgee=(q;u;r),letter(oremptyword)x) if u="andx6="then

if x isnotinL[q℄then

insertthepair(x;1) inL[q℄

elsein rementthe eld number oftheletterxin L[q℄

if L[q℄hasmorethanoneelementorifqisinitialor nalthen lo al [q℄ "

elselo al [q℄ theuniqueletterofL[q℄

Update-table-Head(edgee=(q;u;r),letter(oremptyword)x) Wehaveu=xu

0

,where u 0

isa niteword,wheneverx6=" if x6="then

de rementthe eld number oftheletterxin L[q℄ if this eldisequalto 0then

removethepair(x;0)from L[q℄ if u

0 =bu

00

wherebisaletterofAthen if bisnotinL[q℄then

insertthepair(b;1)in L[q℄

elsein rementthe eldnumber oftheletterb inL[q℄ if L[q℄hasmorethanoneelementorifqisinitialor nalthen

lo al [q℄ "

elseif L[q℄ hasexa tlyoneelementthen lo al [q℄ theuniqueletterofL [q℄

(13)

We analyze now the omplexity of our algorithm. We denote by jSj the ardinalityofasetS. Astheautomatonistrim,jQjjEj+1. Wealsodenote byjE

"

jthe ardinalityofthe urrentautomatonA "

. WealwayshavejE "

jjEj buttheautomatonA

"

maybemu hsmallerthanA. WedenoteherebyP the maximallengthofthewordsP(q)forallstatesq.

Proposition7 Fun tion Make-Prefix worksin timeO((P+1)jEj).

Proof. Fun tion Init-Table an be implemented to work in time O(jQj+ jEj). Fun tionsStrongly-Conne ted-ComponentsandFind-Letter an beimplementedtoworkintimeO(jQj+jE

"

j). Fun tionInit-Letterworksin timeO(jQj). Asdis ussedabove,fun tionUpdate-TableworksintimeO(1). Fun tion Move-Letter works in time O(jQj+jEj). Finally the loop in Make-Prefixisexe utedatmostP+1times. The omplexityofouralgorithm isthen O((jQj+jEj)(P +1)+(jQj+jE

"

j)(P +1)). Sin e theautomata onsideredaretrim, jQjjEj+1andthe omplexityisthusO((P+1)jEj). 

LetS bethesumofthelengthsofthelabelsofalledgesoftheautomaton. Thespa e omplexityofthealgorithmisO((jQjjAj)+jEj+S).

5 A knowledgements

WethankChristianCho rutandMaximeCro hemoreforusefuldis ussionsand omments. ChristianCho rutpointedouttoustheina ura yofthealgorithm of[13℄intheparti ular asewheretheautomatonhasanemptylabelled y le. Wealsothanktheanonymousrefereesfortheirrelevantremarks.

Referen es

[1℄ Aho, A. V., Hop roft, J. E., and Ullman, J. D. The Design and Analysisof Computer Algorithms. AddisonWesley,1974.

[2℄ B

eal,M.-P. CodageSymbolique. Masson,1993.

[3℄ B 

eal,M.-P.,andCarton,O.Determinizationoftransdu ersover nite andin nitewords.Te h.Rep.99-12,I.G.M.,UniversitedeMarne-la-Vallee, 1999.

[4℄ Berstel, J. Transdu tions and Context-Free Languages. B.G.Teubner, 1979.

[5℄ Breslauer,D. ThesuÆxtreeofatreeandminimizingsequential trans-du ers.InCPM'96(1996),vol.1075ofLe tureNotesinComputerS ien e, Springer-Verlag,pp.116{129.

(14)

du ers. Theoret. Comput.S i., 191(1998),131{144.

[7℄ Choffrut, C. Contribution a l'etude de quelques familles remarquables de fon tions rationnelles. Thesed'



Etat,UniversiteParisVII,1978.

[8℄ Choffrut,C.AgeneralizationofGinsburgandRose's hara terizationof gsmmappings.InICALP'79 (1979),vol.71ofLe tureNotesinComputer S ien e,Springer-Verlag,pp.88{103.

[9℄ Cormen, T.H.,Leiserson,C.E., andRivest, R.L. Introdu tion to Algorithms. MITPress,1990.

[10℄ Cro hemore, M., Han art, C., and Le roq, T. Algorithmique du Texte. Vuibert,2000. toappear.

[11℄ Frougny,C.Numerationsystems.InAlgebrai Combinatori sonWords, M.Lothaire,Ed.Cambridge,2000. toappear.

[12℄ Mohri, M. Minimization of sequentialtransdu ers. In CPM'94 (1994), M. Cro hemoreandD. Gus eld, Eds.,vol.807of Le ture Notesin Com-puter S ien e,Springer-Verlag,pp.151{163.

[13℄ Mohri, M. Minimizationalgorithmsfor sequentialtransdu ers. Theoret. Comput. S i.,234(2000),177{201.

[14℄ Ro he, E., and S habes, Y. Finite-State Language Pro essing. MIT Press,Cambridge,1997, h.7.

Figure

Figure 2: The prex automaton of A.

Références

Documents relatifs

Key words: computational process, computational model, abstract state machine, finite-level quantum system, qubit, Kraus' family, quantum operation, abstract quantum

At a certain voltage to the electrodes in the surface layer were able to observe autowaves, which are shown in Figure 1 (a, b, c, d).. The described near-electrode layer of

Though the complexity of Brzozowski’s algorithm is exponential in the worst case, our adaptation is linear in time and quadratic in space, using both automata constructions and

Example 2.1- Consider the automaton A pictured in Figure 1 where the initial state is 1 and the final state is 4. The prefix automaton of A is pictured in Figure 2... The

A path 7 in the automaton is successful if it starts at the initial state and if inf(7) is an accepting subset of states. Many different kinds of acceptance conditions have been

Therefore, we aim to develop an approximated Constrained Subsequence Automaton with quorum q (d csa q ) on the basis of these results, where the incremental and on-line update can

In addition, even if p is not realized by a PRFA or is empirically estimated, our algorithm returns a PFA that realizes a proper distribution closed to the true distribution..

The paper is organized as follows: in Section 2, we recall the definition of a PFA and the basic Spectral learning algorithm; in Section 3 we define PRFA and a provable