A quadratic algorithm for road coloring
The Road Coloring Theorem states that every aperiodic directed graph with constant out-degree has a synchronized coloring. This theorem had been conjectured during many years as the Road Coloring Problem before being settled by A. Trahtman. Trahtman'…
Authors: Marie-Pierre Beal, Dominique Perrin
A quadratic al gorithm for road colori ng Marie-Pierre B ´ eal and Dominique P e rrin ∗ † No v em b er 20, 2021 Abstract The Road Coloring Theorem states that every ape r io dic directed graph with constant out-degree ha s a s ynchronized coloring. This the- orem had been conjectured during man y y ears as t he Road Coloring Problem b efore b eing settled by A. T rahtman. T rahtman’s proo f leads to an a lgorithm that finds a synchronized la beling with a cubic worst- case time complexity . W e show a v ariant of his cons tr uction with a worst-case complexity which is quadratic in time and linear in space. W e a lso extend the Ro a d Co loring Theorem to the p erio dic case. 1 In tro duction Imagine a ma p with roads whic h are colored in suc h a wa y that a fixed sequence of colors, called a homing sequence, lea ds t he tra v eler to a fixed place whatev er the starting p oint is. Suc h a coloring of the roads is called sync hronized and findin g a sy n c hronized coloring is called the Road Coloring Problem. In terms of graphs, it consists in finding a sync h ronized lab eling in a directed graph. The Road Coloring Theorem s tates that every ap erio dic directed graph with constan t out-degree h as a syn c hronized colo ring (a graph is ap erio dic if it is strongly connected and the gcd of the length of the cycles is equal to 1). It h as b een conjectured und er the name of the Road Coloring Problem b y Adler, Go o dwin , and W eiss [2], and solv ed for many particular t y p es of automata (see for in s tance [2], [23], [9], [19], [16], [25]). T rahtman settled the conjecture in [29]. In this pap er , by Road Coloring Problem we understand the algorithmic pr oblem of find in g a syn c hronized coloring on a giv en graph (and not the existence of a p olynomial algo rithm w hic h is s olv ed by the Road Coloring Theorem). ∗ Universit ´ e P aris-Est, Lab oratoire d’informatique Gaspard-Monge CNRS UMR 8049, 5 b oulev ard Descartes, 77454 Marne-la-V all´ ee, F ran ce, { beal,p errin } @univ- m lv .fr † This w ork is supported by F rench National Agency (AN R) through ”Programme d’Inv estissemen ts d’Avenir” (Pro ject ACR ONYME n ◦ ANR-10-LA BX-58). 1 Solving the Road Coloring problem in eac h particular case is not only a pu zzle but h as many applications in v arious areas lik e co ding or design of computational systems. These systems are often mo d eled by finite-state automata ( i.e. graphs with lab els). Due to some noise, the system ma y tak e a w r ong transition. This n oise m a y for in stance r esult fr om the phys- ical prop erties of sensors , from un reliabilit y of computational h ardw are, or from insufficient sp eed of the computer with resp ect to the arriv al rate of input symb ols. It turn s out that the asymptotic b eha vior of syn c hronized automata is b etter than th e b eha vior of uns y n c hronized ones (see [12]). Sync hronized automata are thus less sensitive to th e effect of noise. In the domain of co d ing, automata with outpu ts ( i.e. transducers) can b e used either as enco ders or as deco ders. When they are synchronized, the b ehavi or of the co der (or of the d eco d er ) is impro v ed in the pr esence of n oise or err ors (see [4], [18]). F or instance, the w ell-kno wn Huffman compression sc heme leads to a s y n c hronized deco der p ro vided the lengths of th e co de- w ords of the Huffman co de are relativ ely prime. It is also a consequence of the Road Coloring Theorem th at co d ing sc hemes for constrained c hannels can hav e sliding blo ck deco ders and synchronized enco ders (see [1] and [21]). T rahtman’s p ro of is constructiv e and leads to an algo rithm that finds a sync hronized lab eling w ith a cub ic worst-c ase time complexit y [29, 31]. The algorithm consists in a sequence of flips of edges going out of some state so that the resulting automaton is sync hronized. One first searc hes a s equ ence of flips leading to an automaton whic h has a so-ca lled stable pair of states ( i.e. with go o d sync hronizing p rop erties). One then computes the quotien t of the au tomaton b y the congruence generated by the stable pairs. The pro cess is then iterated on this smaller automaton. T rahtman’s metho d for finding the sequence o f flips leading to a stable p air has a worst-ca se quadratic time complexit y , whic h mak es his algorithm cubic. In this pap er, we d esign a worst-ca se li near time algorithm for find ing a s equence of fl ips until the automaton has a stable pair. Th is makes the algorithm for computing a syn c hronized coloring quadr atic in time and linear in space. The sequence of flips is obtained by fi xing a color, sa y r ed, and by considering the red cycle s formed with red edges, t aking i nto acco unt the p ositions of the ro ots of red trees attac hed to eac h cycle. The prize to pay for decreasing the time complexit y is some more complication in the choic e of th e fl ips. W e also extend the R oad Coloring Th eorem to p eriodic graphs b y sho wing that T r ah tman’s algorithms pro vides a minimal-rank coloring. Another pr o of of this result using semigroup to ols, obtained indep en den tly , is giv en in [7]. F or related results, s ee also [30 ] and [17]. The complexit y of sync hronization problems on automata has b een al- ready studied (see [20] for a su rv ey). It is well-kno w n that there is an O ( n 2 ) algorithm to test whether an n -state automaton on a fi xed-size alphab et is sync hronized. The complexity of computing a sp ecific synchronizing wo rd is O ( n 3 ) (see [14]). Ho we v er, the complexit y of finding a sync hronizing wo rd 2 of a giv en length is NP-complete [14] (see also [24], [27]). The complexity of pr oblems on automata has also b een stud ied for random automata (see [8]). Sev eral results pro v e that, u nder appropriate hyp otheses, a random irreducible automaton is syn chronized [15], [28], and [22]. The a v erage time complexit y of these pr ob lems do es not seem to b e kno wn. In particular, we do not kno w the a v erage time complexit y of the Road Coloring Pr oblem. The article is organized as follo ws. In Section 2, we give some d efinitions to formulat e the p roblem in terms of fin ite automata instead of graph s. In Section 3 w e describ e T rah tman’s algorithm and our v ariant is detailed in Section 4. W e give b oth an informal d escription of the algorithm with pictures illustrating the constructions, and a pseud o co de. The time and space complexit y of the algorithm are analyzed in Section 5. The p eriod ic case is treated in Section 6. A preliminary v ersion of this pap er was p osted in [3]. 2 The Road Colo ring T heorem In order to formulate th e R o ad Color ing P r oblem we introdu ce the notation concerning automata. Let A b e a fi nite alphab et and let Q b e a fi nite set. W e denote b y A ∗ the s et of w ords o v er A . A (finite) automaton A = ( Q, E ) o v er the alphab et A with Q as set of states is a giv en by a set E of edges which are trip les ( p, a, q ) where p, q are states and a is a sym b ol from A called the label of the edge. N ote that no initial or final states are sp ecified. Let F b e the multiset f ormed of the pairs ( p, q ) obtained from the set E b y the m ap ( p, a, q ) 7→ ( p, q ). The m ultigraph ha ving Q as set o f vertice s and F a s set of edges is called th e underlying gr aph of A . A p ath in the automaton is sequence of consecutiv e edges. The lab el of the path (( p i , a i , p i +1 ) 0 ≤ i ≤ n is the w ord a 0 · · · a n . The state p 0 is its origin and p n +1 is its end. The leng th of the p ath is n + 1. Th e path is a cycle if p 0 = p n +1 . An au tomaton is deterministic if, for eac h s tate p and eac h letter a , there is at most one edge starting at p and lab eled with a . It is c omplete deterministic if, f or eac h state p and eac h lette r a , there is exactly one edge starting at p and lab eled with a . This imp lies that for eac h state p and eac h w ord w there is exactly one path starting at p and lab eled with w . T he en d of th is uniqu e path is denoted by p · w . An automaton is irr e ducible if its underlyin g graph is strongly connected. The p erio d o f an automaton is the gcd of length of its cycles. An automaton is ap erio dic if it is irr educible and of p erio d 1 1 . 1 Note that this notion, whic h is usual for graphs, is not the notion of ap erio dic automata used elsewhere and which refers t o the p eriod of words lab eling the cycles (see e.g. [13 ]). 3 A synchr onizing wor d of a complete determin istic automaton A = ( Q, E ) is a word w ∈ A ∗ suc h that f or eve ry pair of states p, q ∈ Q , one has p · w = q · w . A syn c hronizing w ord is also called a r eset se quenc e [1 4], or a magic se qu enc e [5, 6], or also a homing wor d [26]. An automaton which h as a sync h ronizing w ord is call ed synchr onize d (see an example on the righ t part of Fig. 1). Tw o automata whic h hav e isomorphic u nderlying graphs are called e qu i v- alent . Hence t w o equ iv alen t automat a differ only b y the labeling of their edges. In the sequel, w e shall consider only complete deterministic automata. Prop osition 1. A synchr onize d c omplete deterministic automaton is ap e- rio dic. Pr o of. W e assum e that the automaton h as at least one edge. Let ( p, a, q ) b e an edge of th e automaton. Let w b e a synchronizing w ord fo cus ing to a state r . S ince the graph is strongly connected, there is a wo rd v such that from r · v = p . Th us p · aw v p = p · w v p . Th e lengths of the cycles from p to p lab eled aw v and w v differ b y 1. This implies that the p erio d of automaton is 1. The R o ad Coloring The or em can b e stated as follo ws. Theorem 2 (A. T r ah tman [29]) . Any ap erio dic c omplete deterministic au- tomaton is e quivalent to a synchr onize d one. 1 2 3 4 1 2 3 4 Figure 1: Two complete ap erio d ic deterministic automata ov er the alphab et A = { a, b } . A thic k red p lain edge is an edge lab eled b y a wh ile a th in blu e dashed edge is an edge lab eled by b . Th e automaton on the left is n ot sync hronized. The one on the right is sync hronized. F or instance, the word aaa is a sync hronizing w ord. The tw o automata are equiv alent since th eir underlying graph are isomorphic. A trivial case f or solving the Road Coloring Th eorem is the case where the automaton has a lo op edge around some state r [23]. Ind eed, since the graph of the automato n is strongly connected, there is a spanning tree ro oted at r (with the edges of the tree oriented to w ards the ro ot). Let u s lab el the edges of this tree and the loop b y the letter a . This coloring is sync hronized by the word a n − 1 , where n is the n umber of states. 4 3 An algorithm for find ing a sync hronized coloring T rahtman’s pro of of Th eorem 2 is constructiv e an d giv es an algorithm for finding a lab eling (also called a coloring) which makes the automaton syn- c hronized provided it is ap erio dic. In the s equ el A denote s an n -state complete deterministic au tomaton o v er an alphab et A . W e fix a particular letter a ∈ A . Edges lab eled b y a are also called r e d e dges or a - e dges . The other ones are called blue o r b - e dges . A pair ( p, q ) of states in an automaton is synchr onizable if there is a w ord w with p · w = q · w . It is well- known that an automaton is sync hronized if all its pairs of states are synchronizable (see for instance Prop osition 3.6.5 in [4]). A pair ( p, q ) of states in an automaton is stable if and only if, for an y word u , the pair ( p · u, q · u ) is sync hronizable. Th is notion was introd uced in [10]. In a synchronized automaton, an y pair of states is stable. Note that if ( p, q ) is a stable pair, then for an y wo rd u , ( p · u, q · u ) is also a stable pair, hence the termin ology . Note also that if ( p, q ) and ( q , r ) are stable pairs then ( p, r ) is also a s table pair. It follo ws that the relation d efined on th e set of states b y p ≡ q if ( p, q ) is a s table p air is an equiv alence relatio n. As obs erv ed in [19, Lemma 2], th is r elation is a congruence ( i.e. p · u ≡ q · u wh enev er p ≡ q ) called the stable p air c ongruenc e . More generally , a congruence is stable if an y pair of states in th e same class is s table. Th e congruence g e ner ate d by a stable pair ( p, q ) is th e least congruence suc h that p and q b elong to the same class. It is a stable congruence. Giv en a congruence on the states of an automaton, w e denote by ¯ p the class of a state p . If A = ( Q, E ) is an auto maton, the quotient of A by a stable pair congruence is the automaton B whose states are the classes of Q under the congruence. The edges of B a re the triples ( ¯ p, c, ¯ q ) where ( p, c, q ) is an edge of A . T he automaton B is complete deterministic w h en A is complete deterministic. The automaton B is irreducible (resp. ap eriod ic) w hen A is irreducible (resp. ap erio d ic). The follo wing Lemma was obtained by Culik et al. [11]. W e repr o- duce the pro of since it helps under s tanding T raht man’s algorithm (see the pro cedur e FindSynch ronizedColoring b elo w). Lemma 3 (Culik et al. [11]) . If the quotient of an automaton A by a stable p air c ongruenc e is e quivalent to a synchr onize d automaton, th en ther e is a synchr onize d automato n e quivalent to A . Pr o of. Let B b e the quotien t of A by a stable congruence and let B ′ b e a synchronized automaton equiv alent to B . W e define an automaton A ′ equiv alent to A as follo ws. The num b er of edges of A going out of p and ending in states b elonging to a same class ¯ q is equal to the num b er of edges of B (and thus B ′ ) going out of ¯ p and endin g in ¯ q . W e define A ′ b y lab eling 5 these edges according to th e lab eling of corresp on d ing edges in B ′ . The automaton B ′ is a quotien t of A ′ . Let us sho w that A ′ is syn c hronized. Let w b e a sync hronizing w ord of B ′ and r the s tate ending any path lab eled by w in B ′ . Let p, q b e t wo states of A ′ . Then p · w and q · w b elong to the same congruence cla ss. He nce ( p · w , q · w ) is a stable pair of A ′ . Therefore ( p, q ) is a synchronizable pair of A ′ . Since all pairs of A ′ are sync hronizable, A ′ is synchronized. T rahtman’s algorithm for findin g a syn c hronized coloring of an ap erio d ic automaton A consists in fi nding an equiv alent automaton A ′ of A whic h has at least on e stable pair ( s, t ), then in r ecursiv ely fin ding a sync hronized coloring B ′ for the quotien t automaton B by the congruence generated by ( s, t ), and fin ally in lifting up this coloring to the initial automaton as follo ws. If there is an edge ( p, c, q ) in A but no edge ( ¯ p, c, ¯ q ) in B ′ , then there is an edge ( ¯ p, d, ¯ q ) in B ′ with c 6 = d . Then w e flip the lab els of the t w o edges lab eled c and d going out of p in A . The algorithm f or fin ding a sync hronized coloring is describ ed in the follo wing pseudo code. The p ro cedure FindSt a bleP air , whic h finds an equiv alent automato n w h ic h has a stable pair of s tates, is describ ed in the next section. The pro cedu re Merge computes the qu otien t of an automaton b y the stable congruence generated by a stable pair of states. The pro cedure Upda te up dates some data needed for the computation as d escrib ed in Section 5.1. FindSynchronizedColoring (aperio dic automa to n A , q uo tient automaton B ) 1 B ← A 2 while (size( B ) > 1) 3 do U pda te( B ) 4 B , ( s, t ) ← FindSt abl eP air( B ) 5 lift the color ing up from B to the automaton A 6 B ← Merg e ( B , ( s, t )) 7 return A The termination of the algorithm is guaran teed b y the fact that the num- b er of states of the qu otien t automaton of B is strictly less than th e num b er of states of B . T he computation of the qu otien t automaton (p erformed b y the P ro cedure Merge ) is describ ed in S ection 7. 4 Finding a stable pai r In this section, we consider an ap eriod ic complete d etermin istic automaton A o v er the alphab et A . W e design a linear-time algorithm for finding an equiv alent automaton wh ic h has a stable pair. In ord er to describ e the algorithm, we giv e some definitions and notation. 6 Let R b e the subgraph of the graph of A made of the r ed edges. The graph R is a disjoint union of connected comp on ents called clusters . Since eac h state has exactly one outgoing edge in R , eac h cluster con tains a unique (red) cycle with trees attac hed to the cycle at their ro ots. If r is the ro ot of suc h a tree, its childr en are th e states p su c h that p is n ot on the a red cycle and ( p, a, r ) is an edge. If p, q b elong to the same tree, p is an anc estor of q (or q is a desc endant of p ) in the tree if there is a red path f rom q to p . No te that in these trees, the edges are oriented from the c hild to the parents and the p aths from the descendant to the ancestors. If q b elongs to some red cycle of length greater than 1, its pr e de c e ssor is the unique state p b elonging to the same cycle such that ( p, a, q ) is an edge. In the case the length of the cycle is 1, we set that the predecessor is q itself. F or eac h sta te p b elonging to s ome cluster, w e define the level of p as the distance b et w een p and the ro ot of the tree con taining p . If p b elongs to th e cycle of th e cluster, its level is th us n ull. Th e level of an automa ton is the maxima l lev el of its states. A maximal state is a state of m aximal lev el. A maximal tr e e is a tree conta ining at least one maximal state and ro oted at a state of lev el 0. A maximal r o ot is the r o ot of a maximal tree and a maximal child of a maximal r o ot r is a c hild of r h aving at least one maximal state as descendan t. The algorithm for fin ding a coloring which has a stable pair relies on the follo wing k ey lemma due to T raht man [29]. It uses the notion of min im al images in an automaton. An i mage in an automaton A = ( Q, E ) is a set of states I = Q · w , w here w is a word and Q · w = { q · w | q ∈ Q } . A minimal image in an automaton is an image wh ic h do es not pr op erly con tain another image. In a n irreducible auto maton t w o minimal images ha v e the same cardinalit y whic h is called the minimal r ank of A . Also, if I is a minimal image and u is a word, then I · u is again a minimal image and the m ap p → p · u is one-to-one fr om I on to I · u . Note that the h yp otheses in the statemen t b elo w dep en d on the c hoice of th e letter a definin g the red edges. Lemma 4 (T rahtma n [29]) . L et A b e an i rr e ducible c ompl ete deterministic automato n with a p ositive level. If al l maximal states in A b elong to the same tr e e, then A has a stable p air. Pr o of. Since A is irreducible, th ere is a minimal image I con taining a max- imal state p . Let ℓ > 0 the level of p ( i.e. the distance b etw een p and the ro ot r of the un iqu e maximal tree). Let u s assume th at there is a state q 6 = p in I of lev el ℓ . T h en the cardinal of I · a ℓ is strictly less than the card inal of I , wh ic h con tradicts the minimality of I . Thus all states but p in I ha v e lev el strictly less than ℓ . Let m b e a common m ultiple of the lengths of all red cycles. Let C b e the red cycle con taining r . Let s 0 b e the p redecessor of r in C and s 1 the c hild of r cont aining p in its su btree. Since ℓ > 0, w e ha ve s 0 6 = s 1 . Let 7 J = I · a ℓ − 1 and K = J · a m . Sin ce the le ve l of all states of I but p is less than or equal to ℓ − 1, the set J is equal to { s 1 } ∪ R , where R is a set of states b elonging to the red cycles. Since for an y state q in a red cycle, q · a m = q , we get K = { s 0 } ∪ R . Let w b e a word suc h that Q · w is a min imal image. F or any w ord v , the minimal images J · v w a nd K · v w ha v e the same cardinal equal to the cardinal of I . W e claim that the s et ( J ∪ K ) · v w is a minimal image. Indeed, J · v w ⊆ ( J ∪ K ) · v w ⊆ Q · v w , h ence al l three are equal. But ( J ∪ K ) · v w = R · v w ∪ s 0 · v w ∪ s 1 · v w . This forces s 0 · v w = s 1 · v w since the card inalit y of R · v w cann ot b e less th an the cardinalit y of R . As a consequence ( s 0 · v , s 1 · v ) is sync hronizable a nd thus ( s 0 , s 1 ) is a stable pair. In the sequel, we call Condition C the assumption of Lemma 4: al l maximal states b elong to the same tr e e . In the subsections b elo w, we describ e sequences of flips of edges that mak e the resulting equiv alen t automaton satisfy Condition C and hence ha v e a stable pair. W e consider sev eral cases corresp onding to the geometry of th e automaton. 4.1 The case of n ull maximal level In this section, w e assume that the lev el of the a utomaton is ℓ = 0. The subgraph R of red edges is a disjoint un ion of cycles. A set of edges going out of a state p is call ed a bunch if these edges all end in a s ame s tate q . No te that if a state q h as tw o in coming bu nc hes fr om t w o states p, p ′ , then ( p, p ′ ) is a stable pair. If the set of outgoing edges of eac h state is a bunc h, then there is only one red cycle, and the automaton is not ap erio dic unless the trivial case where the length of this cycle is 1. W e can th us assume that there is a state p whose set of outgoing edges is not a bu nc h. Th ere exists b 6 = a and q 6 = r suc h that ( p, a, q ) and ( p, b, r ) are edges. W e flip these t w o edges. This give s an automaton A whic h satisfies Condition C . Let s b e the state whic h is the predecessor of r in its red cycle. It f ollo w s from the pro of of Lemma 4 that the pair ( p, s ) is a s table pair. This case is d escrib ed in the ps eu do co de Le velZeroFlipEdges wh ere GetPredeces sor ( r ) returns the predecessor of r on its red cycle. The function Lev elZeroFlipEdges ( A ) retur ns an au tomaton equiv alen t to A together with a stable pair. 8 LevelZeroFlipEdges (automaton A of level ℓ = 0) 1 for each state p on a red cycle C 2 do i f the set of outgoing edges of p is no t a bunch 3 then let e = ( p, a, q ) and f = ( p, b, r ) b e edges with b 6 = a and q 6 = r 4 Flip ( e, f ) 5 s ← GetPredecessor ( r ) 6 return A , ( p, s ) 7 return E rror ( A is no t ap er io dic) The pro cedur e Fl ip ( e, f ) exchanges the lab els of tw o edges e, f . It also p erforms the corresp ond in g u p date of data as explained in S ection 5.1. 4.2 The case of non-n ull maximal lev el In this section, we assume that the lev el of the automaton is ℓ > 0. 4.2.1 Main trea tmen t W e describ e a sequence of flips of edges suc h that the automaton obtained after this sequence of fl ips has a unique maximal tree. Note that the lev els and other us eful data will not b e r ecomputed after eac h flip (which w ould increase the time complexit y to o muc h). Let C b e a red cycle con taining a m aximal tree T ro oted at r . W e denote by r 1 = r , r 2 , . . . r k the maximal ro ots of C in the order giv en b y the orien tation of the red edges of the cycle. F or k > 1 and 1 ≤ i ≤ k we denote b y I ( r i ) the set of stat es con tained in the red simple path from the ro ot r j with j = ( i − 1 mo d k ) + 1 to r i with r j included and r i excluded. F or k = 1 w e define I ( r ) as the set of all states of C . Similarly , for k > 1 and 1 ≤ i ≤ k we d en ote b y J ( r i ) the set of states con tained in the r ed simple path from the ro ot r j with j = ( i − 1 mo d k ) + 1 to r i with r j excluded and r i included. F or k = 1 we d efine J ( r ) as the set of all s tates of C . W e denote by s 0 the p redecessor of r in C . If the length of C is 1, s 0 = r . W e denote by S ( r ) the set of maximal c hildren of r ( i.e. whic h are ancestors of some maximal state). Let ρ b e the cardin ality of S ( r ). F or eac h s in S ( r ), we choose a maximal state p in the subtree ro oted at s (see Fig. 2). There may b e sev eral p ossible c hoices for the state p and w e select one of them arb itrarily . W e denote by P ( r ) the set of these maximal states. Th is set has cardinalit y ρ . The k ey id ea, in order to guarant ee th e g lobal linear co mplexit y , is to p erform op eratio ns for eac h m aximal r o ot r , whose time complexit y is linear in the n um b er of no des b elonging to trees attac hed to the states con tained in J ( r ). Since the automaton i s ir r educible, f or ea c h p ∈ P ( r ) there is at least one blue edge end ing in p . E ach blue edge ( t, b, p ) endin g in a state p ∈ P ( r ) 9 r s 2 p 2 s 1 p 1 s 0 r k t 1 r s 2 p 2 s 1 p 1 s 0 r k Figure 2: On the left part the figure, the d ashed (blue) edge ending in p 1 has t yp e 1 wh ile th e one ending in p 2 has type 3. On the right part, the set L s 1 of dashed (blue) edges cov er all maximal s tates of th e subtr ee r o oted at the child s 1 . can b e of o ne of the follo wing t yp e dep ending on the p ositio n of t in th e graph: • t yp e 0: t is n ot in the same cluster as r , or t h as a p ositiv e lev el and t is not an ancestor of p in T . • t yp e 1: t is in the same cluster as r , has a null lev el, and t is outside the in terv al I ( r ). • t yp e 2: t is in the same cluster as r , has a null lev el, and t is con tained in th e in terv al I ( r ). This includ es the particular case where k = 1 and t = r . • t yp e 3: t is an ancestor of p in T and t 6 = r . Note that it is p ossible that t = p . In this case th e edge ( t, b, p ) has t yp e 0 since t has a p ositiv e lev el. A pro cedure FindEdges ( r ), that will b e describ ed later in detail (see Section 4.2.2), firs t flips some edges and return s a v alue of on e of the follo w- ing f orms. • A pair (0 , e ), where e is an ed ge of t yp e 0. • A triple (1 , e, f ), w h ere e, f are tw o edges o f t yp e 1 or 2 ending in distinct states of P ( r ). • A pair (2 , e ), where e is an edge of type 1 or 2. Moreo v er, in this case, the pro cedur e mo d ifies the tree T in such a w a y that r has a u nique maximal c hild. • A pair (3 , e ), where e is an edge of t yp e 3 starting at a state whic h is an ancestor of all maximal no d es of T . 10 F or eac h maximal ro ot r , the p ro cedure F lipEdges ( A , r ) r eturns either an automaton equiv alent to A together with a stable p air, or an automaton equiv alent to A together w ith one edge ( t r , b r , p r ). Its execution dep end s on the v alue return ed by FindEdges ( r ) according to the follo wing four cases describ ed b elo w. After runn ing FlipEdges ( A , r ) on eac h maximal ro ot, we obtain either an automaton satisfying Condition C ( i.e. whic h has a stable pair) or an automaton w here eac h maximal ro ot r has a unique maximal c hild and such th at th e p otent ial fl ip of ( t r , b r , p r ) with the red edge starting at t r mak es the ro ot r not maximal an ymore. In the first case, our goal is ac hiev ed. In the lat ter case, we flip the blue edge ( t r , b r , p r ) a nd the red one sta rting at t r for all maximal ro ots r but one . W e get an equiv alen t automaton whic h has unique m aximal tree and t hus has a stable pair b y Lemma 4. The combinatio n of all these transformations is realized by the pro cedur e FindSt ab leP air giv en at the end of this section. The p ossible v alues return ed by the pro cedur e FlipEdges ( A , r ) are the follo wing. • Case 0. The v alue retur ned by FindEdges ( r ) is (0 , e ) with e = ( t 1 , b 1 , p 1 ) of t yp e 0. T he pr o cedure F lipEdges ( A , r ) returns th e au- tomaton obtained by flipping the edge ( t 1 , b 1 , p 1 ) and the r ed edge going out of t 1 . Th is automaton is equiv alen t to A and s atisfies Con- dition C . Ind eed, one ma y easily chec k that, after the flip , all states of maximal lev el b elong to the same tree as p 1 . 1 9 10 8 r s 2 p 2 s 1 p 1 s 0 5 15 16 t 1 17 3 18 19 2 1 9 10 8 r s 2 p 2 s 1 p 1 s 0 5 15 16 t 1 17 3 18 19 2 Figure 3: The picture on the left illustrates Case 1.1. T h e edge ( t 1 , b 1 , p 1 ) if of t yp e 1. After flipping the edge ( t 1 , b 1 , p 1 ) and the red edge going out of t 1 , w e get the automaton on th e right. It satisfies the Cond ition C , i.e. it has a u nique maximal tree (here ro oted at r ). Maximal states are colored and the (dashed) b -edges of the automaton are not all repr esented. • Case 1. The v alue r eturned b y FindEdges ( r ) is (1 , e 1 , e 2 ), with e 1 = ( t 1 , b 1 , p 1 ), e 2 = ( t 2 , b 2 , p 2 ) of t yp e 1 or 2. Recal l that p 1 6 = p 2 and that 11 b 1 , b 2 6 = a . – Case 1.1. If e 1 (or e 2 ) has typ e 1, the same conclusion as in Case 0 holds by flipping the edge ( t 1 , b 1 , p 1 ) and the red edge going out of t 1 , as is sho wn in Fig. 3. – Case 1.2. In the case b oth edges e 1 , e 2 ha v e t yp e 2 and t 1 6 = t 2 , without loss of generalit y , w e m a y assume that t 1 < t 2 in the in terv al I ( r ) (see Fig. 4). W e flip the edge ( t 1 , b 1 , p 1 ) and the red edge going out of t 1 . W e den ote by T ′ the tree ro oted at r after this flip. ∗ Case 1.2.1. If the height of T ′ is greater than ℓ , the automa- ton satisfies Condition C (see the r igh t part of Fig. 4). ∗ Case 1.2.2. Oth er w ise the height of T ′ is at most ℓ (see the left part of Fig. 5). In that case, w e also fl ip the edge ( t 2 , b 2 , p 2 ) and the red edge going out o f t 2 . The new equiv alen t au- tomaton satisfies Condition C (see the r igh t part of Fig. 5). The computation of the size of T ′ is detailed in S ection 5. 1 9 10 8 r 21 s 2 p 2 s 1 p 1 t 2 20 5 15 t 1 17 22 3 18 19 2 1 9 10 8 r 21 s 2 p 2 s 1 p 1 t 2 20 5 15 t 1 17 22 3 18 19 2 Figure 4: The picture on the left illustrates Case 1.2.1 of the main treatmen t. There are t w o ed ges ( t 1 , b 1 , p 1 ), ( t 2 , b 2 , p 2 ) of t yp e 2. The heigh t of the tree T ′ obtained after flipping the edge ( t 1 , b 1 , p 1 ) and the red ed ge going out of t 1 , is 3, which is greater than the maximal lev el. W e get a unique maximal tree ro oted at r in the same cluster. Th e picture on the righ t illustrates th e result. – Case 1.3. In this case b oth edges e 1 , e 2 ha v e t yp e 2 and t 1 = t 2 . W e denote by s 1 (resp. s 2 ) the c hild of r ancestor of p 1 (resp. p 2 ). W e den ote b y T 0 the tree ro oted at r obtained by the p oten tial flip of ( t 1 , b 1 , p 1 ) and the red ed ge going out of t 1 , keeping only r and the su btree ro oted at the c hild s 0 . The no des of th e tree T 0 ro oted at r a re represented in s almon in the left part of Fig. 6. This step again needs a computation of the height of T 0 explained 12 1 9 10 8 r 21 s 2 p 2 s 1 p 1 t 2 20 5 t 1 17 22 3 18 19 2 1 9 10 8 r 21 s 2 p 2 s 1 p 1 t 2 20 5 t 1 17 22 3 18 19 2 Figure 5: Th e picture on the left illustrates Case 1.2.2. Th e t w o edges ( t 1 , b 1 , p 1 ), ( t 2 , b 2 , p 2 ) are of type 2. The heigh t of the tree T ′ obtained after flipping the edge ( t 1 , b 1 , p 1 ) and the red edge going out of t 1 , is equal to ℓ = 2. In this case, w e also flip th e edge ( t 2 , b 2 , p 2 ) and the red edge going out of t 2 . W e get a u nique m aximal tree ro oted at r in the same cluster. The picture on the righ t giv es the resulting clus ter. in th e complexit y issue. Case 1.3 occurs when ρ > 1, k = 1 and t 1 = r . In the particular case where the length of C is 1, the tree T 0 is reduced to the no de r (it corresp on d s to the Case 1.3.2 b elo w). ∗ Case 1.3.1. If the h eigh t of T 0 is greater th an the height of T , we flip ( t 1 , b 1 , p 1 ) and the red edge going out of t 1 . The equiv alent automaton satisfies Cond ition C . ∗ Case 1.3.2. I f the heigh t of T 0 is less than the heigh t of T , w e fl ip ( t 1 , b 1 , p 1 ) and the red edge going out of t 1 . W e then call again the pro cedure FlipEdges ( A , r ) with th is new red cycle. This time the (new) tree T 0 has the same height as T . Hence this call is done at most on e time for a give n maximal ro ot r . ∗ Case 1.3.3. Finally , we consider the case wher e the heigh ts of T and T 0 are equal (see the left part of Fig. 6). · Case 1.3.3. 1. I f the set of outgoing edges of s 0 is a bu nc h and there is a state s i ∈ S ( r ) whose set of outgoing edges is also a b unch, w e get a trivial stable pair ( s 0 , s i ). · Case 1.3.3. 2. I f the set of outgoing edges of s 0 is a bu nc h and, for an y state s ∈ S ( r ), the set of outgoing edges of s is not a bu nc h (as in the left part of Fig. 6), we flip ( t 1 , b 1 , p 1 ) and the red edge going out of t 1 . The (new) tree T 0 (obtained b y the p oten tial flip of ( t 2 , b 2 , p 2 ) and the red ed ge going out of t 1 , keeping only r an d the 13 subtree ro oted at the c hild s 1 ) has the same height as T . W e then call again the pro cedure FlipEdges ( A , r ) with this new red cycle. This time the h eigh t of the new tree T 0 is still equal to the height of T and th e set of outgoing edges of the predecessor of r on th e cycle is n ot a bunch. This call is thus p erformed at most one time. · Case 1.3.3.3. If the set of outgoing edges of s 0 is not a bunch, let ( s 0 , b 0 , q 0 ) b e a b -edge going out of s 0 with q 0 6 = r . If q 0 do es not b elong to T , w e get an equiv alen t automaton satisfying Cond ition C by flipping ( s 0 , b 0 , q 0 ) and the red edge going out of s 0 . If q 0 b elongs to T , w e flip ( s 0 , b 0 , q 0 ) and the red edge going out of s 0 . W e also flip ( t 1 , b 1 , p 1 ) and the red edge going out of t 1 if q 0 is n ot a descendant of s 1 , or ( t 1 , b 2 , p 2 ) and the red edge going out of t 1 , in the opp osite case. Note that s 0 6 = t 1 since the height of T 0 is equal to the non-null heigh t of T . W e get an equiv alen t automaton satisfying Condition C (see the r igh t part of Fig. 7). 1 9 10 8 r 21 s 2 p 2 s 1 p 1 s 0 20 5 t 1 17 22 3 18 19 2 1 9 10 8 r 21 s 2 p 2 s 1 p 1 s 0 20 5 t 1 17 22 3 18 19 2 Figure 6: The picture on the left illustrates Case 1.3.3.2 of the main treat- men t. Th e tw o edges ( t 1 , b 1 , p 1 ) and ( t 1 , b 2 , p 2 ) are of typ e 2. Let T 0 b e th e tree ro oted at r obtained by the p oten tial flip of ( t 1 , b 1 , p 1 ) and the red edge going out of t 1 , kee ping only r and the su btree ro oted at the c hild s 0 . Th e no des of the tree T 0 ro oted at r are rep resen ted in salmon in th e left p art of the figure. T he state s 0 is a bun c h. After flippin g the edge ( t 1 , b 1 , p 1 ) and the r ed edge going out of t 1 , w e get the automaton pictured in the right part of the figur e. The tree T ′ 0 is no w tree r o oted at r obtained by the p oten tial flip of ( t 1 , b 2 , p 2 ) and the r ed edge going out of t 1 , k eeping only r and the subtree ro oted at the child s 1 . Its state s are colored in salmon. The h eigh t of T ′ 0 is 2. • Case 2. W e now come to the case w here the v alue returned b y Find- 14 1 9 10 8 r 21 s 1 p 1 s 2 p 2 s 0 20 5 t 1 17 22 3 18 19 2 1 9 10 8 r 21 s 1 p 1 s 2 p 2 s 0 20 5 t 1 17 22 3 18 19 2 Figure 7: The p icture on the left illustrates Case 1.3.3 .3. The t w o edges ( t 1 , b 1 , p 1 ) and ( t 1 , b 2 , p 2 ) are of t yp e 2. Let T 0 b e the tree ro oted at r obtained by the potentia l flip of ( t 1 , b 1 , p 1 ) and the red edge going out of t 1 , kee ping only r and the subtree ro oted at the c hild s 0 . The no des of th e tree T 0 ro oted at r are represente d in salmon in the left part of the figure. The state s 0 is n ot a bun c h: it has a b -edge ( s 0 , b 0 , q 0 ) with q 0 = s 2 . After flipping the edge ( t 1 , b 1 , p 1 ) and the red edge going out of t 1 , and flipp ing ( s 0 , b 0 , q 0 ) and the red edge going out of s 0 , we get a un ique maximal tree ro oted at r in the same cluster (see the righ t part of the fi gure). Edges ( r ) is a p air (2 , e ) with e = ( t 1 , b 1 , p 1 ) of type 1 or 2, and T is mo dified in su c h a wa y that r has a unique maximal c hild, i.e. ρ = 1. – Case 2.1. If ( t 1 , b 1 , p 1 ) has typ e 1, we flip the edge ( t 1 , b 1 , p 1 ) and the red edge going out of t 1 . W e get a n equiv alen t automa ton satisfying Condition C . – Case 2.2. If ( t 1 , b 1 , p 1 ) has t yp e 2, we den ote by T 0 the tree ro oted at r obtained by the p oten tial flip of ( t 1 , b 1 , p 1 ) and the red edge going out of t 1 , k eeping only r and the sub tree ro oted at the c hild s 0 . Case 2.2 o ccurs when ρ = 1, k = 1 and t 1 = r . In the particular case wh ere the length of C is 1, T 0 is red u ced to the no de r whic h corresp ond s to the Case 2.2.2 b elo w. ∗ Case 2.2.1. If th e heigh t of T 0 is greater than the height of T , we d o the flip and the equiv alen t automaton satisfies Condition C . ∗ Case 2.2.2. I f the heigh t of T 0 is less than the heigh t of T , w e do not d o the flip, and retur n the automaton together with the edge ( t 1 , b 1 , p 1 ). Note that a p ossible future flip of ( t 1 , b 1 , p 1 ) and the red edge starting at t 1 mak es the r o ot r not maximal an ymore. ∗ Case 2.2.3. W e no w come to the case where the h eigh t of T 0 is equal to the heigh t of T . 15 · Case 2.2.3. 1. I f the s et of outgoing ed ges of s 0 and s 1 are bunches, there is a trivial stable pair ( s 0 , s 1 ). · Case 2.2.3. 2. I f the set of outgoing edges of s 0 is a bu nc h and the set of outgoing edges of s 1 is not a bunch (see the left part of Fig. 8 ), w e flip the edge ( t 1 , b 1 , p 1 ) and the r ed edge going out of t 1 . W e then call the pro cedu re FlipEdges ( A , r ) w ith this new red cycle. The ro ot r has no w a unique c hild ( s 1 ) ancestor of maximal state wh ose set of outgoing edges is a bunc h (see the righ t part of Fig. 8 ). This call is th us p er f ormed at most one time. · Case 2.2.3.3. Finally , if s 0 is a n ot a bu nc h, let ( s 0 , b 0 , q 0 ) b e a b -edge with q 0 6 = r . If q 0 do es not b elong to T w e flip the ed ge ( s 0 , b 0 , q 0 ) and the red edge going out of s 0 . The e quiv alen t automato n s atisfies Condition C . It q 0 b elongs to T and is not a descendan t of s 1 , we fl ip the edge ( t 1 , b 1 , p 1 ) and the r ed edge going out of t 1 , and w e also flip th e edge ( s 0 , b 0 , q 0 ) and the red ed ge going out of s 0 . The equiv alen t automaton satisfies C ondition C . If q 0 b elongs to T an d is a descendant of s 1 , w e return the au tomaton toge ther with the ed ge ( s 0 , b 0 , q 0 ). 1 9 10 8 r 21 s 1 p s 0 20 t 1 15 16 6 17 3 18 19 2 1 9 10 8 r 21 s 0 p s 1 20 t 1 15 16 6 17 3 18 19 2 Figure 8: The picture on the left illustrates Case 2.2.3.2 of the main treat- men t. The edge ( t 1 , b 1 , p 1 ) has t yp e 2. After flipping the edge ( t 1 , b 1 , p 1 ) and the red ed ge going out of t 1 , we get the automaton on the righ t part of the fi gu r e. The ro ot r has a new single c hild s 1 ancestor of a m aximal state, whose s et of outgoi ng edges is a bunch. Th e new tree ro oted at r has here the same level ℓ = 2 as b efore and F lipEdges ( A , r ) is called a second an d last time. • Case 3. If the v alue retur ned b y FindEdges ( r ) is an edge ( t 1 , b 1 , p 1 ) of type 3 and t 1 is an ancestor of all m aximal no d es of T the pr o cedure FlipEdges ( A , r ) returns this edge. 16 After runn ing FlipEdges ( A , r ) on all maximal ro ots, w e get either an automaton with a s table pair, or an automaton where eac h cluster fulfills the f ollo w ing conditions. • the ro ot r of eac h maximal tree h as a unique maximal child; • for eac h maximal ro ot r , there is an edge ( t r , b r , p r ) suc h that the p oten tial flip of ( t r , b r , p r ) and the r ed edge starting at t r mak es the ro ot r not m aximal an ymore. If the latter case, we flip the blue edge ( t r , b r , p r ) and the red one starting at t r for all maximal ro ots r b ut one. W e get an equiv alent automaton whic h satisfies Condition C as is shown in Fig. 9. Th e pseu d o co de for this fin al treatmen t is giv en in p ro cedure FindSt abl eP air . FindSt ableP air (automato n A ) 1 if the maxima l level ℓ = 0 2 then return LevelZeroFlipEdges ( A ) 3 else for each maximal ro o t r 4 do A , S ← FlipEdges ( A , r ) 5 if S is a (sta ble) pair of sta tes ( s, t ) 6 then return A , ( s, t ) 7 else ( S is a b -edge ( t r , b r , p r )) set e ( r ) = S 8 for ea ch max imal r o ot r 6 = r 0 9 do flip the e dg e e ( r ) and the r ed edg e s ta rting at t r 10 s ← GetPredecessor ( r 0 ) 11 t ← the child of r 0 ancestor of p r 0 12 return A , ( s, t ) 17 1 9 10 8 r s 1 p s 0 20 t 1 15 16 6 17 3 18 19 2 1 9 10 8 r s 0 p s 1 20 t 1 15 16 6 17 3 18 19 2 Figure 9: T he p icture on the left illustrates the case where FlipEdges ( A , r ) has retur ned a b -edge e ( r ) for all maximal ro ots r . W e flip e ( r ) and the r ed edge starting a t the same state for all but one m aximal ro ot r . Th e new cluster is pictured on the r igh t part of the figure. It has a unique maximal tree. By Lemma 4 the pair (6 , 15) is stable. 4.2.2 The auxilia ry pro cedure FindEdges In this section, w e describ e the pro cedure F indEdges ( r ) which is a prelim- inary step of the pro cedure FlipEdges ( r ). Let r b e a maximal ro ot, S ( r ) b e the set of maximal c hildren of r . F or eac h s in S ( r ), w e c ho ose a m aximal state p in the s u btree ro oted at s and w e denote by P ( r ) the set of these maximal states (see Fig. 2). Recall that the p r o cedure FindEdges ( r ) flips some edges and r etur ns an equiv alent automaton toget her with one or t w o edges of th e f ollo wing forms. • One edge e of t yp e 0. • Two edges e, f of t yp e 1 or 2 endin g in d istinct states of P ( r ). • One edge e of type 1 or 2. Moreo v er, in this case, the p ro cedure mo difies the tree T in such a wa y that r h as a u nique maximal c hild. • One edge e of typ e 3 starting at a state whic h is an ancestor of all maximal no des of T . F or eac h maximal c hild s , we denote b y T s the subtree of T rooted at s . The p ro cedure FindEdges ( r, s ) computes a list L s of b -edges ( q, b, p ), where p is a maximal no de of T s and q is an ancestor of p in T distinct from r . The starting states q of edges of this list c over the maximal n o des of T s in th e foll o wing sense: for eac h maximal no de p ′ in T s , there i s a u nique edge ( t, b, p ) ∈ L s suc h that t is an ancestor of p ′ (see for instance the right part of Fig. 2). The list L s is computed by scanning at most one time eac h no de of the tree T s . F or ea c h maximal lea f p , w e follo w t he red edges up 18 to s and either find s or an already scanned no de, or fi nd a no de with an outgoing b -edge ending in p . In the latter case, this edge is add ed to L s and w e con tin ue with another maximal leaf. In the case the list L s do es not co v er all maximal no des of T s , and since the graph of the automaton is strongly connected, the pro cess fin d s an edge ( t s , b s , p s ) where p s is a maximal no de of T s , of t yp e 0, 1 or 2. If there is a maximal c hild s suc h that an edge ( t s , b s , p s ) of typ e 0 is found, then FindEdges ( r ) returns th is edge. Otherwise, if th ere are tw o maximal children s 1 6 = s 2 suc h that t wo ed ges ( t s 1 , b s 1 , p s 1 ), ( t s 2 , b s 2 , p s 2 ) of type 1 or 2 are found , then FindEdges ( r ) returns these t wo edges. If there is a maximal c hild s 1 suc h an edge e = ( t s 1 , b s 1 , p s 1 ) of t yp e 1 or 2 and cov ering lists L s for the other maximal c hildren s 6 = s 1 are foun d, th en we perf orm the follo wing flips. F or an y maximal c hild s 6 = s 1 and an y edge ( t, b, p ) ∈ L s , we fl ip the edge ( t, b, p ) and the r ed edge going out of t . W e up date the data of the trees attac h ed to the n o des f rom p to t in the new red cycle created b y the flip. After th is transformation the no de r has s 1 as unique m aximal c hild. The pro cedure FindEdges ( r ) returns th e edge e of t yp e 1 or 2 and r has a unique maximal c hild. Finally , if one obtains co v ering lists for all maximal c hildren, then, for all these c hildren s but one, say s 1 , w e flip eac h edge ( t, b, p ) ∈ L s and the r ed edge going out of t . W e also flip all edges ( t, b, p ) ∈ L s 1 but one, ( t 1 , b 1 , p 1 ). W e up date the data of the trees attac hed to the no des from p to t in the new r ed cycle created b y eac h flip. The pro cedure FindEdges ( r ) returns the edge ( t 1 , b 1 , p 1 ) of typ e 3. Its starting state t 1 is d isctinct from r ans is an ancestor of all maximal states of T . 5 The c omplexit y issue In this section, w e establish the time and sp ace complexit y of our algorithm. W e den ote b y k t he size of the alphab et A and by n the n umb er of states of A . Since A is complete deterministic, it h as exactly k n edges. 5.1 Data struct ures and their updating Some d ata attac h ed to the states is useful to obtain th e claimed complexit y . This data is up dated after the computation of eac h qu otient automaton with the pro cedure U pda te with a time complexit y whic h is lin ear in the size of the q u otien t automaton. The edges of the automaton can b e stored in tables indexed by the states and lab els. Th e u p d ating pro cedure computes the lev el of eac h state, the ro ot of its tree in its cluster. It also computes a list of m aximal ro ots an d the pred ecessor of a s tate on the cycle. The fun ction GetPredece ssor ( q ) returns the predecessor of state q on its red cycle in constant time. 19 One computes • for eac h r o ot of a tree T , the heigh t of T , • for eac h maximal r o ot, the list of its maximal children, • for eac h maximal c hild, the list of the maximal no d es b elonging to the subtree ro oted at this c hild. This d ata can b e moreo v er u p d ated in time linear in the size of the tree. W e also main tain an inv erse structure of the qu otien t automaton. Givi ng a lab el c and a state q , it giv es, for eac h letter c , an u nordered list of states p suc h that there is an edge ( p, c, q ) in the qu otien t automaton. The pro cedure Flip ( e, f ) exc hanges the lab els of the tw o edges e = ( p, b, q ) , f = ( p, a, q ′ ). It also up dates in the inv erse structure the lists of edges coming in p and p ′ . Its time complexit y is thus up p er b ounded by the n umber of edges going out of p, p ′ or coming in p, p ′ . 5.2 Complexit y of the algorithm Prop osition 5. The worst-c ase c omplexity of FindS ynchronizedCol- oring applie d to an n -state ap erio dic automaton is O ( k n 2 ) in time, and O ( k n ) in sp ac e. Pr o of. The complexity of FindSynchronizedColoring is at most n times the complexit y of the pro cedur es Upda t e and FindSt ableP air . In d eed, eac h call in the pro cedu r e Merge reduces the num b er of states of the au - tomaton so th at it is called at most n − 1 time s. Since eac h of its ste ps without the recursive calls tak es a time at most k n , t he contribution of Merge in F indSynchronizedColoring is at most k n . As the pr o cedure Upda te has a time complexit y O ( k n ), w e just ha v e to sh o w that the time complexit y of FindSt a bleP air is O ( k n ). Since Le velZeroFlipEdges conta ins only on e Flip call, we sh ow that the calls to F lipEdges ( A , r ) for all maximal ro ots r can b e p erform ed in time O ( k n ). W e first examine the complexit y of the auxiliary step FindEdges ( r ) for a giv en maximal ro ot r . This pro cedure requires a scan of the no d es of trees T s ro oted at the maximal c h ildren s of r together with their outgoing edges. Sin ce the edges cont ained in the lists L s ha v e distinct target s tates in T , the flips of ed ges in L s can b e p erform ed w ith a time complexit y at most E ( r ), where E ( r ) is the n u m b er of edges going out of or coming in a no de of the tree T ro oted by r . In deed, the up date of the inv erse structure for no des in T can b e p erformed one time for all the flips of edges in L s . Note that the u p dating of the d ata after the flips is at most th e size of T . Ind eed, a fter a flip of ( t, b, p ) and ( t, a, p ′ ) only th e no d es b elonging to trees ro oted at no des along the r ed path from p to t are up dated. As a 20 consequence, th e con tribution of the auxiliary step in FindSt ableP air is O ( P r E ( r )) = O (2 kn ). W e no w co me to the complexit y induced by th e main treatmen t. W e denote b y S ect( r ) the num b er of edges coming in or going out o f a n o de b elonging to th e secto r J ( r ), i.e. the no des conta ined in a tree attac hed to a no d e of the cycle b et w een r ′ and r ( r included and r ′ ), where r ′ is the maximal ro ot preceding r on C . Let us compu te f or instance the complexit y of the p ro cedure UniqueChildFlipEdges ( A , r , e = ( t 1 , b 1 , p 1 )) (see S ec- tion 7). It con tains at most tw o fl ip s of edges end ing in T . The heigh t of the tree T 0 is easily computed by scanning all no d es at tac hed to s ome no de of C b etw een r and r ′ ( r and r ′ b oth excluded ). In the case wh ere this heigh t is equal to ℓ and the set of outgoing edges of s 0 is a bunc h, we flip the e dge e . W e p erf orm th e pro cedure UpD a teSect or ( r , e ) for up- dating the data of the no d es con tained in the trees whose ro ots b elong to J ( r ). Then w e call a second (and l ast) time F lipEdges ( A , r ). S ince the time complexit y of UpDa teS ector ( r, e ) is at most S ect( r ), we get that the time complexit y of UniqueChildF lipEdges ( A , r , e ) is also Sect( r ). Sim- ilarly , the time complexit y of th e pro cedur es ChildrenFlipEdgesEqual and ChildrenFlipEdges UnEqual is also S ect( r ). Hence the o v erall time sp en t f or computing FlipEdges ( A , r ) for all maximal ro ots r is O ( P r Sect( r )) = O (2 k n ). The space complexit y is O ( k n ). Indeed, only linear add itional sp ace is needed to p erform all op eratio ns. 6 The c ase of p erio dic graphs Recall th at the p erio d of an automaton is the gcd of the lengths of its cycles. If the automaton A is an n -state complete deterministic irreducible automaton which is not ap eriodic, it is not equiv alen t to a syn chronized automaton. Nev ertheless, the pr evious algorithm can b e mo dified as f ollo w s for fin ding an equiv alen t automaton w ith the min imal p ossible rank. It has a quadratic-time complexit y . PeriodicFindColoring (a uto maton A ) 1 B ← A 2 while (size( B ) > 1) 3 do U pda te( B ) 4 B , ( s, t ) ← FindSt abl eP air( B ) 5 lift the color ing up from B to the automaton A 6 if there is a stable pair ( s, t ) 7 then B ← Mer ge ( B , ( s, t )) 8 else return A 9 return A It may happ en that FindSt ableP air returns an automaton B w hic h has no stable pair (it is made of a cycle where th e set of outgoing edges of an y 21 state is a bu nc h). Lifting up this coloring to th e initial au tomaton A leads to a coloring of the initial automaton whose minimal rank i s equal t o its p erio d. This result can b e stated as the foll o wing theo rem, which extend s the Road Coloring Theorem to the case of p erio d ic graph s. Theorem 6. Any i rr e ducible automato n A is e quivalent to a an automaton whose minimal r ank is the p erio d of A . Pr o of. Let us assume that A is equ iv alen t to an automaton A ′ whic h h as a stable pair ( s, t ). Let B ′ b e the quotient of A ′ b y the congru en ce generated b y ( s, t ). Let d b e the p erio d of A ′ (equal to th e p eriod of A ) and d ′ the p erio d of B ′ . Let us sho w that d = d ′ . It is clear that d ′ divides d (whic h w e d enote d ′ /d ). Let ℓ b e the length of a path from s to s ′ in A ′ , wh ere s ′ is equiv alen t to s . Sin ce ( s, s ′ ) is stable, it is synchronizable. Th us there is a w ord w suc h that s · w = s ′ · w . Sin ce th e automaton A ′ is irr educible, there is a path lab eled b y some w ord u from s · w to s . Hence d/ ( ℓ + | w | + | u | ) and d/ | ( w | + | u | ), implying d/ℓ . Let ¯ s b e the class of s and z b e th e lab el of a cycle around ¯ s in B ′ . Then there is a path in A ′ lab eled by z from s to x , wher e x is equiv alen t to x . Thus d/ | z | . It f ollo w s th at d/d ′ and d = d ′ . Supp ose that B ′ has rank r . Let us show th at A ′ also has rank r . Let I b e a min imal image of A ′ and J b e the set of classes of the states of I in B ′ . Two states of I cannot b elong to the same class since I would not b e minimal otherwise. As a consequence I has the same cardinal as J . Th e set J is a minimal image of B ′ . Ind eed, for any w ord v , the set J · v is the set of classes of I · v wh ic h is a m inimal image of A ′ . Hence | J · v | = | J | . As a consequence, B ′ has rank r . Let us no w assume that A has no equiv alen t automaton which has a stable pair. In th is case, we know that A is made of one r ed cycle where th e set of edges going out of any state is a bunc h. The r an k of this au tomaton is equal to its p erio d which is the length of th e cycle. Hence th e pro cedur e PeriodicFindColoring r eturns an automaton equiv alent to A w hose m inimal r ank is equal to its p erio d . Since the m o dification of FindSynchronizedColoring into Period- icFindColoring d o es not c hange its complexit y , we obtain the follo wing corollary . Corollary 7. Pr o c e dur e PeriodicFindColoring finds a c oloring of min- imal r ank for an n -state irr e ducible automato n i n time O ( k n 2 ) . 7 Pseudo c o de This s ection con tains the pseu d o co de of some m ain p ro cedures. 22 7.1 Pro cedure Merge The computation of the congruence generated by ( s , t ) can b e p erformed by using usu al Union/Find fu nctions computing resp ectiv ely the u nion of tw o classes and th e leader of th e class of a state. A fter merging t w o classes w hose leaders are p and q resp ectiv ely , w e need to merge the classes of p · ℓ and q · ℓ for an y ℓ ∈ A . A pseu d o co de for merging classes is giv en in Pro cedur e Merge b elo w. Mer ge (a utomaton A , stable pa ir ( s, t )) 1 x ← Find ( s ) 2 y ← Find ( t ) 3 if x 6 = y 4 then Union ( x, y ) 5 for ℓ ∈ A 6 do Merge ( A , ( x · ℓ, y · ℓ )) 7 return A 7.2 Pro cedure FlipEdges W e giv e b elo w a pseudo code of th e pr o cedure FlipEdges ( A , r ). F or eac h maximal root r , it returns e ither an automaton e quiv alen t to A together with a stable p air, or an automaton equiv alen t to A to gether with one edge. It p erform s s ome flips dep endin g on the t yp e of the edges return ed by FindEdges ( r ). It calls UniqueChildFl ipEdges ( r , e ) in the case r has a unique m aximal child and e is an edge of t yp e 2 returned b y FindEdges ( r ). It calls Childre nFlipEdgesUneq ual ( A , r ) in the case r has at least t w o maximal children and FindEdges ( r ) r etur n a pair of edges with distinct starting state s. It calls ChildrenFlipEdgesUn equal ( A , r ) in th e case r has at least tw o maximal c hildren and FindEdges ( r ) return s a pair of edges whic h ha v e the same starting state. Recall that GetPredecessor ( r ) returns the predecessor of state r on its red cycle. 23 FlipEdges ( automaton A , ma ximal ro ot r ) 1 result ← FindEdges ( r ) 2 if ( r a unique maxima l child s 1 ) and (r esult 6 = (3 , e )) 3 then if (result = (0 , e ) or (result = (2 , e ) wher e e has type 1) 4 then Fl ip ( e ) 5 return A and the sta ble pair ( s 1 , GetPredecessor ( r )) 6 else (result = (2 , e ) where e has type 2) 7 return UniqueChildFlipEdges ( r , e ) 8 if ( r at least tw o max ima l children) and (result = (1 , e 1 , e 2 ) where e 1 = ( t 1 , b 1 , p 1 ) , e 2 = ( t 2 , b 2 , p 2 ) hav e type 1 or 2) 9 then if t 1 6 = t 2 10 then return ChildrenFlipEdgesU nequal ( r , e 1 , e 2 ) 11 else return ChildrenFlipEdgesEqual ( r, e 1 , e 2 ) 12 if result = (3 , e ) wher e e is an edg e of type 3 13 then return A , e UniqueChildFlipEdges (a utomaton A , maxima l ro o t r , edge e = ( t 1 , b 1 , p 1 ) of type 2) 1 let s 1 be the unique child of r 2 s 0 ← GetPredecessor ( r )) 3 let T 0 be the tree r o oted at r o btained by the p otential flip of e and the red edge going o ut of t 1 , keeping only r and the subtree ro oted at the child s 0 4 if height( T 0 ) > height( T ) 5 then Flip ( t 1 , b 1 , p 1 ) 6 return A and the sta ble pair ( s 1 , s 0 ) 7 if height( T 0 ) < height( T ) 8 then return A and the e dg e e 9 if height( T 0 ) = height( T ) 10 then if the set of o utgoing e dg es of s 0 and s 1 are bunches 11 then return A and the stable pair ( s 0 , s 1 ) 12 if the s et of o utgoing edg es of s 0 is a bunch and the s et of o utgoing edg es of s 1 is no t a bunc h 13 then Flip ( t 1 , b 1 , p 1 ) 14 UpDa teSector ( r , e ) (we still have height( T 0 ) = height( T )) 15 return Fl ipEdges ( A , r ) 16 if the s et of o utgoing edg es of s 0 is no t a bunc h 17 then let ( s 0 , b, q 0 ) a b -edge g oing out o f s 0 with q 0 6 = r 18 if q 0 / ∈ T 19 then Flip ( s 0 , b 0 , q 0 ) 20 if the level of q 0 is p os itive 21 then r 0 ← the r o ot of the tree containing q 0 22 s ← GetPredecessor ( r 0 ) 23 t ← the child o f r 0 ancestor of q 0 24 return A and the sta ble pair ( s, t ) 25 else r 0 ← the r o ot of the tree containing q 0 26 s ← GetPredecessor ( r 0 ) 27 return A and the sta ble pair ( s, s 0 ) 28 else ( q 0 ∈ T and q 0 6 = r ) 29 return A and the edg e ( s 0 , b, q 0 ) 24 ChildrenFlipEdgesEqual (automa ton A , maximal ro o t r , edges e 1 , e 2 ) of type 2 1 set e 1 = ( t 1 , b 1 , p 1 ) and e 2 = ( t 1 , b 2 , p 2 ) 2 s 0 ← GetPredecessor ( r ) 3 let T 0 be the tree r o oted at r o btained o btained by the p otential flip of ( t 1 , b 1 , p 1 ) and the r ed edg e going out of t 1 , keeping only r and the subtree ro oted at s 0 4 if height( T 0 ) > height( T ) 5 then Flip ( t 1 , b 1 , p 1 ) 6 return A and the sta ble pair ( s 1 , s 0 ) 7 if height( T 0 ) < height( T ) 8 then Flip ( t 1 , b 1 , p 1 ) 9 UpDa teSector ( r, e 1 ) 10 return Fl ipEdges ( A , r ) 11 if height( T 0 ) = height( T ) 12 then if the set of o utgoing e dg es of s 0 is a bunch a nd there is a n int eger i ≥ 1 such that the set of outgoing edges of s i is a bunch 13 then return A and the stable pair ( s 0 , s i ) 14 if the s et of o utgoing edg es of s 0 is a bunch and the s ets o f outgoing e dges of s i for i ≥ 1 ar e no t bunch es 15 then Flip ( t 1 , b 1 , p 1 ) 16 UpDa teSector ( r , e 1 ) (w e still hav e heig ht ( T 0 ) = height( T )) 17 return Fl ipEdges ( A , r ) 18 if the s et of o utgoing edg es of s 0 is no t a bunc h 19 then let ( s 0 , b, q 0 ) a b -edge g oing out o f s 0 with q 0 6 = r 20 if q 0 / ∈ T 21 then Flip ( s 0 , b 0 , q 0 ) 22 if the level of q 0 is p os itive 23 then r 0 ← the r o ot of the tree containing q 0 24 s ← GetPredecessor ( r 0 ) 25 t ← the child o f r 0 ancestor of q 0 26 return A and the sta ble pair ( s, t ) 27 else r 0 ← the r o ot of the tree containing q 0 28 s ← GetPredecessor ( r 0 ) 29 return A and the sta ble pair ( s, s 0 ) 30 else ( q 0 ∈ T ) 31 if q 0 is not a des cendant o f s 1 32 then Flip ( t 1 , b 1 , q 1 ) 33 Flip ( s 0 , b 0 , q 0 ) 34 t ← the child o f r a ncestor o f q 0 35 return A and the sta ble pair ( s 1 , t 1 ) 36 else ( q 0 is a descendant of s 1 ) 37 Flip ( t 2 , b 2 , q 2 ) 38 Flip ( s 0 , b 0 , q 0 ) 39 return A and the sta ble pair ( s 1 , s 2 ) The pro cedur e UpD a teSecto r ( r , e = ( t 1 , b 1 , p 1 )) is called after a flip of the edge e and the red edge going out of t 1 . It up dates the data of the no des (and th eir trees attac hed to) along the red path going from p 1 to s 1 , where s 1 is the unique maximal c hild of r . 25 ChildrenFlipEdgesUnequal (automa ton A , maximal ro o t r , edges e 1 , e 2 ) 1 set e 1 = ( t 1 , b 1 , p 1 ) and e 2 = ( t 2 , b 2 , p 2 ) with t 1 6 = t 2 2 if at lea st o ne o f e 1 , e 2 (say e 1 ) has t yp e 1 and s 1 is the child of r a ncestor of p 1 3 then s 0 ← GetPredecessor ( r ) 4 Flip ( t 1 , b 1 , p 1 ) 5 return A and the sta ble pair ( s 0 , s 1 ) 6 else Fl ip ( t 1 , b 1 , p 1 ) 7 let T ′ be the new tree ro o ted a t r 8 if height( T ′ ) > height( T ) 9 then return the sta ble pair ( s 1 , s 0 ) 10 else (height( T ′ ) ≤ height( T )) 11 Flip ( t 2 , b 2 , p 2 ) 12 return A a nd the stable pa ir ( s 1 , s 2 ) A ck now le dgments Th e authors would like to than k Florian Siko ra, Avraham T rahtman, and the anonymous referees f or p oin ting us some missing con- figurations in the algorithm. W e also thank the referees for helping us to impro v e the p r esen tation of the pap er. References [1] R. L. Adler, D. Copp ersmith, and M. Hassner. Algorithms for sliding blo c k co des. IEEE T r ans. Inform. The ory , IT-29:5–22, 1983. [2] R. L. Adler, L. W. Go o d wyn, and B. W eiss. Equiv alence of top olog ical Mark o v shifts. Isr ael J. Math. , 27(1):48– 63, 1977. [3] M.-P . B ´ eal and D. Perrin. A quadratic algorithm for road coloring. CoRR , abs /0803 .0726, 2008. [4] J. Berstel, D. Perrin, and C. Reutenauer. Co des and automata , vo lume 129 of Encyclop e dia of Math ematics and its App lic ations . Cambridge Univ ersit y Press, C am bridge, 2010. [5] M. Bo yle and A. Maass. Expansive inv er tib le onesided cellular au- tomata. J. M ath. So c. Jap an , 52(4):725–7 40, 2000. [6] M. Bo yle and A. Maass. Erratum to: ”Expansive inv ertible onesided cellular automata” [J. Math. So c. Japan 52 (2000), no. 4, 725–740 ]. J. Math. So c. Jap an , 56(1):309 –310, 2004. [7] G. Budzban and P . F einsilver. The generalized road coloring p rob- lem and p erio dic d igraphs. Appl. Algebr a Eng . Commun. Comput. , 22(1): 21–35, 2011. [8] A. Cara y ol and C. Nica ud. Distribution of the n um b er of acc essible states in a r an d om deterministic automaton. In ST ACS , v olume 14 of 26 LIPIcs , pages 194–2 05. Sc hloss Dagstuhl - Leibniz-Zen trum fuer Infor- matik, 2012. [9] A. Carb one. Cycles of r elativ ely prime le ngth and the r oad colo ring problem. Isr ael J. Math. , 123:30 3–316, 2001. [10] K. Cu lik, I I, J. Karh um¨ aki, and J. Kari. Syn c hronized automata and road coloring pr oblem. T ec hnical rep ort, TUCS T ec hnical Rep ort 323, T urku Center for Comp uter S cience, Univ ersit y of T u r ku, 1999. [11] K. Cu lik, I I, J. Karh um¨ aki, and J . Kari. A n ote on synchronized au- tomata and road coloring p roblem. In D evelopments in language the ory (Vienna, 2001) , v olume 2295 of L e ctur e Notes in Comput. Sci. , pages 175–1 85. Sprin ger, Berlin, 2002. [12] B. Delyo n and O. Maler. On the effect s of noise and sp eed on compu- tations. The or et. Comput. Sci. , 129(2):279 –291, 1994. [13] S. Eilenb erg. Automata , L anguages, and M achines. Vol. B . Academic Press, New Y ork, 1976. [14] D. Eppstein. Re set sequen ces for m onotonic automata. SIAM J. Com- put. , 19(3):5 00–510, 1990. [15] C. F. F r eiling, D. S. Jungreis, F. Th´ eb erge, and K. Zeger. Almost all complete binary pr efi x codes h a v e a self-sync hronizing string. IEEE T r ansactions on Information The ory , 49(9 ):2219–2 225, 2003. [16] J. F riedman. On the road coloring problem. Pr o c. Amer. M ath. So c. , 110(4 ):1133–1 135, 1990. [17] N. Jonosk a and S. A. Karl. A molecular compu tation of the road color- ing p r oblem. I n DNA b ase d c omputers, II (P rinc eton, NJ, 1996) , v ol- ume 44 of DIMACS Se r. Discr ete M ath. The or et. Comput. Sci . , p ages 87–96 . Amer. Math. So c., Pro vidence, RI, 1999. [18] H. J ¨ ur gensen . Sy n c hronization. Inform. and Comput. , 206(9-10 ):1033– 1044, 2008 . [19] J. Kari. Synchronizing fin ite automata on Eulerian digraphs. The or et. Comput. Sci. , 295(1-3 ):223–2 32, 2003. [20] J. Kari and M. V. V olk o v. ˇ Cern´ y’s conjecture and the road coloring problem. In H andb o ok of Automata . Europ ean S cience F oundation, 2013. to ap p ear. [21] D. A. Lind and B. H. Marcus. An Intr o duction to Symb olic Dynamics and Co ding . Cam bridge Unive rsity Press, Cam bridge, 1995. 27 [22] C. Nicaud. On the syn c hronization of random deterministic automata. preprint, 2013. [23] G. L. O’Brien. The road-colouring problem. Isr ael J. Math. , 39 (1- 2):145 –154, 1981. [24] J. Olsc hewski and M. Ummels. The complexit y of finding reset words in finite automata. In MFCS , v olume 6281 of L e ctur e Notes in Computer Scienc e , pages 568–579. S pringer, 2010. [25] D. Perrin and M .-P . Sc h ¨ utzen b erger. S ync hronizing p r efix co des a nd automata and the road co loring problem. In Symb olic dynamics and its applic ations , vo lume 135 of Contemp. Math. , pages 295–318. Amer. Math. So c., 1992. [26] I. Pomeranz and S. M. Reddy . Application of homing sequ ences to syn- c hronous sequen tial circuit testing. IEEE T r ans. Computers , 43(5):56 9– 580, 1994. [27] A. Roman. The NP-completeness of the r oad coloring pr oblem. Inform. Pr o c ess. L ett. , 111(7 ):342–3 47, 2011 . [28] E. S. Skv ortso v and Y. Zaks. Syn chronizing random automata. Disc r ete Mathematics & The or etic al Computer Sc i enc e , 12(4):95– 108, 2010. [29] A. N. T rahtman. The road coloring problem. Isr ael J. Math. , 172:51–60, 2009. [30] A. N. T raht man. A partially synchronizing co loring. In Pr o c e e dings of CSR 2010 , v olume 6072 of L e ctur e Notes in Comput. Sc i . , pages 362–3 70. Sprin ger-V erlag, 2010. [31] A. N. T rahtman. An algo rithm for road coloring. In Combinatorial algorithms , vol ume 7056 of L e ctur e Notes in Comput. Sci. , pages 349– 360. Springer, Heidelb erg, 2011. 28
Original Paper
Loading high-quality paper...
Comments & Academic Discussion
Loading comments...
Leave a Comment