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�
Marie-Pierre B
eal InstitutGaspardMonge
UniversitedeMarne-la-Vallee
Olivier Carton InstitutGaspardMonge UniversitedeMarne-la-Vallee
Mar h7, 2001
Abstra t
We present analgorithm for omputingthe prex of anautomaton. Automata onsidered are non-deterministi , labelledonwords, and an have "-transitions. The prex 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 prex of the labels of all paths going from q to an initial or nalstate isempty. The interestofthe omputationofthe prexofan 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 prexoflabelsofpathsgoingfromqtoaninitialornalstate,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, anberstdeterminized(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
sequentialtransdu er,eveniftheoutputlabelsarevariablelengthwords. A hara terizationofminimalsequentialtransdu erswasrstgivenin[7℄. A pro eduretoprodu eaminimalsequentialtransdu eristhereindi ated. Itisin parti ularshownin[7℄thattheminimalsequentialtransdu erisobtainedintwo steps. Therstoneis the omputation ofthe prexautomatonof theoutput automatonofthetransdu er. These ondstepisa lassi alminimizationofthe transdu erobtainedattheendoftherststep,seenasanordinarynitestate automaton. The prex of an automaton anbeinterpretedas an automaton with the sameunderlying graph, same behaviour but produ es its output as soonaspossible. Itsname omesfromthefa tthatforanystateq,thelongest ommonprexP(q)oflabelsofpathsgoingfromqtoaninitialornalstateis empty.
Therstalgorithmof omputationoftheprexofanautomatonappearsin [12℄and [13℄. The onstru tionis there alled aquasi-determinization. It has beennoti edbyMohrithattherststepoftheminimizationofsequential trans-du ersisindependentfromthenotionoftransdu ers. Thequasi-determinization isanalgorithmthatworksonnitestateautomata.Itkeepsthegraphofan au-tomatonand hangesonlythelabelsoftheedges. Roughlyspeaking,itpushes thelabelsoftheedgesfromthenalstatestowardstheinitialstatesasmu has possible. ThealgorithmofMohrihasatime omplexityO((P+1)jEj),where EisthesetofedgesandP themaximumofthelengthsofP(q)forallstatesq. WeassumeherethatthenumberofstatesjQjislessthanthenumberofedges. Anotheralgorithm for omputingthe prex ofautomaton hasbeenpresented in[5℄and[6℄. Theapproa hofthisalgorithmisreallydierentfromours. 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 prex 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
algo-algorithm onsistsinde reasingby1thevalueP atea hstep. Wepresentour algorithmforsequentialtransdu ersbutit anbedire tlyextendedtothe ase ofsubsequentialtransdu ers(see[7℄ or[4℄for thedenition ofasubsequential transdu er).
InSe tion2,were allsomebasi denitionsfrom automatatheoryandwe dene the prexautomaton of an automaton. The omputation algorithm of theprexofanautomatonispresentedinSe tion3. The omplexityisanalyzed in Se tion 4. In that se tionsomedata stru turesare des ribed whi h anbe usedtogettherighttime omplexityofthealgorithm.
2 Prex of an automaton and appli ations
Inthesequel,A denotesanite alphabet and" istheemptyword. Awordu isaprex of awordv ifthere is awordw su h that v =uw. The wordw is denoted by u
1
v. The longest ommon prex of aset of wordsis the longest wordwhi hisprexofallwordsoftheset.
Anautomaton overA
is omposedofasetQofstates,asetEQA
Q ofedges andtwosetsI;F Qofinitial andnal states. An edgee=(p;u;q) frompto q isdenoted byp
u
!q, thewordubeingthelabeloftheedge. The automatonisniteifQandEarenite. 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 anal state. The languageor set of words re ognized(ora epted)byanautomatonisthesetoflabelsofa eptingpaths. Anautomatonisdeterministi ifitislabelledbylettersofanitealphabet A, ifithasoneinitialstateandifforea hstatepandea h letterainA, thereis atmostoneedgep
a
!qforsomeq.
We now dene theprex automatonof a given automatonA. This prex automatonhasthesamegraphasA, but the labelsof theedges are hanged. However the labels of the a epting paths remain un hanged and the prex automaton re ognizes the same words. Furthermore, for any state q of the prex automaton the longest ommon prex of the labels of all paths going fromqtoaninitialornalstateisempty.
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 ommonprexofthelabelsofallpathsgoingfromqtoaninitialornalstate. RemarkthatP(q)="ifq isinitialornal.
The prex automaton of A is theautomaton A 0 =(Q;E 0 ;I;F) dened as follows. E 0 =fq P(q) 1 uP(r) !rjq u !risanedgeofAg:
One may easily he k that if q u
onsistent.
NotethatapathlabelledbywfromqtorinAbe omesapathlabelledby P(q)
1
wP(r)from qto r in theprexautomaton. If thispath isa epting,q isinitialandrisnalandthusP(q)andP(r)arebothempty. Thenthelabel ofthe pathin the prexautomaton isthesame asin A. The label ofa y le ofAis onjugatedtoitslabelintheprexautomaton. Inparti ulartheempty labelled y lesoftheprexautomatonarethesameastheonesof A.
By onstru tionthe longest ommon prexof thelabelsofall pathsgoing fromqtoaninitialornalstateisemptyin theprexautomaton.
Our denition of the prex automaton allows edges oming in an initial state. Inmost ases,there isnoneandforea hnon-initial stateq,P(q)is the longest ommonprexofthelabelsofallpathsgoingfrom qtoanalstate.
The wordsP(q) arethe longestwordssu h that P(q) =" ifq is initial or naland su hthat P(q)is aprexof uP(r) forany edgeq
u
!r. Indeed,if a fun tionP
0
mapsanystateqtoawordsu hthatthesetwo onditionsaremet, thenP
0
(q)isaprexofP(q)foranystateq.
1 2 3 4 ba " " a a a Figure1: An automatonA. 1 2 3 4 baa " " a "
Figure2: TheprexautomatonofA.
Example1 ConsidertheautomatonA pi turedin Figure 1where theinitial state is 1 and the nal state is 4. The prex automaton of A is pi tured in Figure2.
quentialandsubsequentialtransdu ers. Atransdu erisdened 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 prex automatonof the output automaton of thetransdu er. These ond stepisaminimization oftheresultingtransdu er, onsideredasaniteautomaton.
Wereferto [12℄forexamplesofminimization ofsequentialtransdu ers.
3 Computation of the prex of an automaton
Inthis se tion, we des ribean algorithmwhi h omputesthe prexof an au-tomaton. The automaton A = (Q;E;I;T) is anon-deterministi automaton whoseedgesare labelledbywordsoveranitealphabet A. Thelabels anbe theemptywordand y leswithemptylabelsareallowed.
Werstdes ribetheprin ipleofthealgorithm. IfqisastateofA,were all that P(q) denotes the longest ommon prex of the labels of all paths going fromq to aninitialornal state. Wedenoteby p(q)therst 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)whoseedgesaredened asfollows:
E 0 =fq p(q) 1 up(r) !rjq u !risanedgeofAg:
Itre ognizesthesamelanguageasAandsatises P A
0 =P
A
1. Byiterating thispro ess,wegettheprexautomaton.
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. Werst 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)
" omputeitonlyforthestates [q℄.
Atthebeginningofthe omputation,all ellsletter[q℄aresettothedefault value>whi h standsfor undened. Duringthe omputation, thesevaluesare hanged into symbolsof A[f"g. Let X be the set A[f";>g. Wedene 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℄℄isrstsettotheinf 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
" " 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),whereuisaniteword,the following two operationsare performed. The letter (orempty word)p( [r℄) is addedattheendofu. Thentherstletter(oremptyword)p( [q℄)isremoved
nonempty,thenp( [q℄)istherstletterof 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 andsatisesP A 0 =P A 1.
Proof. Letw bethelabel ofapath from aninitial stateito anal 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.
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. Therstonerepresentstheedgesofemptylabelgoingoutof q,thatistheedgesthatalsobelongtoA
"
. These ondonerepresentstheedges ofnon-emptylabelgoingoutofq.
Inorderto ompute,forea hstateq,lo al (q)ina onstanttime,wemaintain anarrayL indexedbyQdenedasfollows:
L[q℄ isthe list of pairs(a;n) with a2A;n >02N, su h that q hasat leastoneoutgoingedgelabelledbyawordwhoserstletterisaandsu h thatnisthepositivenumberofedgesgoingoutofqandwhoserstletter isa.
ontains". Thuslo al (q)is"ifL[q℄hasmorethanoneelementorifqisinitial ornal. ItistheletteraifL [q℄ ontainsexa tlyonepair(a;n)andqisneither initialnornal. 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: aeld label whi h ontainstheletter,aeldnumber that ontainsthenumberofedgesgoingout ofqwhoserstletterislabel,aeldstate whi h ontainsthestateqsu hthat the ellbelongsto L[q℄,and nally elds next andprev that givetheindex of thenext(respe tivelyprevious)elementinthesamelist. The ellofindexqof thearrayListheindexinT oftherstelementofL[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 rementationoftheeldnumber ofthe ellofagiven labelin agivenlistarealsodonein a onstanttime. Indeed,to in rementthe eldnumber oftheletterainL[q℄, onein rementstheeld 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 theeldslabel 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℄ >
if aisnotin L [q℄then
insertthepair(a;1) inL[q℄
elsein rementtheeldnumber oftheletterain L[q℄ if L[q℄hasmorethanoneelementorifqisinitialornalthen
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 rementtheeld number oftheletterxin L[q℄
if L[q℄hasmorethanoneelementorifqisinitialornalthen lo al [q℄ "
elselo al [q℄ theuniqueletterofL[q℄
Update-table-Head(edgee=(q;u;r),letter(oremptyword)x) Wehaveu=xu
0
,where u 0
isaniteword,wheneverx6=" if x6="then
de rementtheeld 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 rementtheeldnumber oftheletterb inL[q℄ if L[q℄hasmorethanoneelementorifqisinitialornalthen
lo al [q℄ "
elseif L[q℄ hasexa tlyoneelementthen lo al [q℄ theuniqueletterofL [q℄
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
WethankChristianChorutandMaximeCro hemoreforusefuldis ussionsand omments. ChristianChorutpointedouttoustheina 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 ersovernite andinnitewords.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.
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. Guseld, 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.