外文文献 Factorizing words over an ordered alphabet_第1页
外文文献 Factorizing words over an ordered alphabet_第2页
外文文献 Factorizing words over an ordered alphabet_第3页
外文文献 Factorizing words over an ordered alphabet_第4页
外文文献 Factorizing words over an ordered alphabet_第5页
已阅读5页,还剩14页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

JOURNAL OF ALGORITHMS 4,363-381 (1983) Factorizing Words over an Ordered Alphabet JEAN PIERRE DWAL Laboratoire dInjonnatique, Fact such is the characteriza- tion of the left factors of Lyndon words which is used as a basis for the algorithms presented further. A complete study of this type of property appears in 5. The second section presents the algorithms of factorization of a word into Lyndon words. Two variants of this algorithm are described. They differ by the use in the second of an auxiliary table which plays a role which is similar to the “failure function” used in the Knuth-Morris-Pratt algorithm 6. A preliminary version of these algorithms has been presented in 4. The third section presents three applications of the factorization algo- rithm: the first one is the computation of the minimum suffix of a word; the second, of the maximum suffix. The third one is the computation of the least circular shift of a word. This problem has been already considered in 2 and also in 8. I. FACTORIZING INTO LYNDON WORDS We consider a fixed alphabet A which is a totally ordered set. We denote by A* the free monoid over the set A. A+ is A* minus the empty word. The free monoid A* is ordered by lexicographic order. Therefore, for u, u E A* one has u 1, ukuk E L. 366 JEAN PIERRE DUVAL It is a particular case of the above property that: ForwEL,aEA,k landw a, wa 4 P. Proof. Let a E A with a a. For h E A*, we have that (uu)zuzh 1 and u,a,u; E L. Then (u,uu;)u,u is in P - L, and according to Lemma 1.6, we have that a, = u. Therefore, we have that w has the form (uo)u, where U, u, k has the respective value, either u = ,a, u = u;, k = k, if u; is nonempty, or u is the empty word u = u,a,v(, k = k, + 1 if u; is empty. In both cases we have that uu E L, u E A + and k 1. Therefore w E S. Now then, we have P C S. 0 Therefore, to recognize if a word is a possible prefix of a Lyndon word we have to recognize if it is in S. Lemma 1.6 gives us a method to do this by reading the word from left to right. This the basic idea used in Section II. The proof of the following result can be found in 7. THEOREM 1.8 (CHEN, Fox, LYNDON). Any word w E A* admits a unique factorization. w = w*w*. . . wm (1.3) 368 JEAN PIERRE DUVAL such that each wi (1 Q i 6 m) is a Lyndon word and The decomposition (1.3) will be called in the sequel the standard factoriza- tion of the word w. We denote it by CFL(w) = w,w2, w,. It is not difficult to see that such a factorization exists. In fact, in any factorization of w into Lyndon words which does not satisfies (1.2) we can group two consecutive factors u, o with u wi . . . 2 wm. Therefore w, is the minimum suffix of w. This proves (1). Assume that s is strictly longer than wm. Then i 1. Therefore, w,! d wY . . G w, and w, wz. Therefore CFL(w) = w,CFL(w). 0 PROPOSITION 1.11. Let w = (uuv)uah with u, u, h E A*, a, a E A, q 2 1 and uau E L. Let w, = wz = . . . = w9 = uav. We haue that CFL(uav)%) = w,wz . . . w9 CFL( u) and, for a a CFL( w) = w,w*. . . wq CFL( uuh) whatever h E A*. Proof. Since a Lyndon word has no proper prefix and suffix, the longest prefix of (UUU)U which is in L is a prefix of uuu. Therefore it is uao. According to Proposition 1.10, we have that CFL(UU)U) = w, CFL(uao)-u) and, by induction for q 2 2, CFL(tuu)u) = w,wz. w,CFL(u). Assume a a, according to Lemma 1.6, (uuu)quah 4 P (whatever h E A*). Therefore, the longest prefix of w which is in L is a prefix of (uuu)Ju. The same arguments as above lead us to CFL(w) = w,w*. w,CFL(uah). 0 Now then, Proposition 1.11 and Lemma 1.6 give a method for factorizing a word into Lyndon words by reading it from left to right. This is done in Section II. But, before we do it, let us see the problem of minimum suffix. It is obviously related; according to Proposition 1.9 the minimum suffix of a word is the last term of the factorization. We denote by minsuf(w) the minimum nonempty suffix of w E A+. PROPOSITION 1.12. kt uv E L with u, o E A+. Then, minsuf(u) is a prefix of u. Prooj: Let s = minsuf(u). We have that s 6 u. If s * u and s is not a prefix of u, then so a, minsuf(uuu)*u) = minsuf(sh) whatever h E A*. ProoJ: For a a, according to Proposition 1.11, the last term in the standard factorization of w is the last term in the factorization of dh. Therefore minsuf(uau)quah) = minsuf(uuh). Let s be a suffix of u longer than s. We have that su uj (or j = n + 1). We have that a,. . . uj,- i, is the first factor in the standard factorization of a,. . . a,. The other factors are obtained by factorization uj,- ,+ , . . . a,. The variable k is introduced (k = j - i) in order that the remaining suffix is uk+ , . . . a,. The prefix a,. . . uk is no more considered. FACTORIZING WORDS OVER AN ORDERED ALPHABET 371 At this step the corresponding property for (2.1) is a,+, . . . ai-, = ak+j-i+l . . . aj.e1 and ak+l-” ajwi E L. (2.1) And, for k i we have that (2.1) holds for the values i = k + f j - k and jzj. Then, Algorithm 2.1 is as follows: Algorithm 2.1 Input: a word string a,. . . a, of letters over A. output: the sequence FACT = (k, k,. . . , k,) such that, for wl = a,. . . ak, w2 = ak,+, . . . ak,. . .) w, = ak,_,+ 1 . a, one has CFL(a, . . . a,) = w,w*. . . Wm. (2.4 The method is described as follows: FACT: sequence of integers: begin FACT: = the empty sequence; k: = 0 whilek-cndobegin i: = k + 1; j: = k + 2; 99: case “compare a,: :aj” of 1 ai uj or j = n + 1) : (repeat k: = k + (j - i); add k in FACT until k i) endcase endwhile end Let us prove the correctness of the above program. Let k, i, and j be the respective values of k, i, and j at the first time we enter the while loop with k * 0. Thus, i and j are the values of i and j at the first time we have that a, aj or j = n + 1. 372 JEAN PIERRE DWAL Since k = 0 fromj = 2 to this step, we may ignore the variable k in a first analysis. And show that (2.1) holds from j = 2 to j. For i = 1 and j = 2, a,. . . ai- j and aj- ;+, , . . aj-, are the empty word anda,. uj- ; is reduced to one letter a,. Therefore, (2.1) holds. Then assume that (2.1) holds at step j. The comparison is between the letters ai and uj. For ai = aj, (2.1) holds with the new respective values i + 1 andj + 1 for i andj. (2.3) This is quite clear. It is the justification for case 2 statement in the program. For the current values i and j we define q(i, j), r(i, j), u(i, j), a(i, j), and v(i, j) as follows: j- 1 4= - I I j-i r = mod( j - 1, j - i), a = a, and v = ar+2. ajei. Since (2.1) holds we have that uav=a,.ajbiEL; a = ai and a, Then, we have that 24 = a,. . . a, (2.4) . uj-, = (r it is the first time that k * 0 when entering the while loop. At this step the situation is as follows: We have in FACT the k, k, . . . , k, corresponding to the first q factors in (2.2). The remaining factors are those of the standard factorization of uk,+, . . . a,. I P-9) ujp+*. . . ujt-, = ff,. . . ur, with r = j - 1 - k. Then, u, . . . ak is no more considered, and the process continues for Uk+,. a,. The corresponding property to (2.1) is now (with k = k) uk+,. Ui-1 =Uk+j-i+l- Uj-1 and ak+l* k+j-i E L. (2.1) THEOREM 2.1. Algorithm 2.1 computes the standard factorization of a,. . . a, as denoted by (2.2). It requires no more than 2n comparisons between two letters and uses only three variables. Pro05 Let k, i, and j be the respective values of k, i, and j at the first time we enter the while loop with k f 0. It follows from the above discussion that we have in FACT the values k, k, . . . , k, corresponding to the first q factors as defined in (2.2). Remaining factors may be obtained by factorizing uk,+, . . . a,. Note that at this step the number of times we have “compare a,: : uj” is j - 1 : j - 2 with j = 2 to j - 1 and a, = uj or ui aj, or j = n + 1. According to k = q( j - i) with 374 JEAN PIERRE DUVAL q = (j - l)/(j - i)J we have that j - 1 ajorj=n+ l:(repeatk:=k+(j-i);add k in FACT eudcase endwhile untilki;ifk=j- lthenj:=i+ 1) end (“ifj G (n + 1) dlv 2 then” is optional Let k, i, andi be the respective values of k, i, and j at the first time we enter the while loop with k * 0 in Algorithm 2.2. The process from the starting point to this step is just the same as for Algorithm 2.1, except that we have affected some values to f. Therefore the above discussion for Algorithm 2.1 is still correct at this step. Then the process differs. In Algorithm 2.1 we restart with i = k + 1 and j = k + 2. Then we rescan the word from akp+, to ajf. And we have that ak,+ ,. ajf-, = a ,. a, according to (2.9). FACTORIZING WORDS OVER AN ORDERED ALPHABET 375 Let us define the table f by Forj = 2toj,(2.1)holdsfori =fj. Note that f is uniquely defined. (2.11) Proof Suppose that for some j, we have that (2.1) holds for i = i, and for i = i,(i, aj or j = n + 1. A new factor is obtained. If the new value k is j - 1, then charge the letter aj; in this case j is increased by one and a, is no more charge. If the new value k is such that k -C j - 1, then charge the new factor; it has length j - i and, since k aj: (k: = Mi +j - i; if k = j - 1 then be- gin Mj: = k; j: = j + 1 end) end endcase endwhile Let i and j be the respective values of i and j at the first time we find a, aj. From j = 2 to j, Algorithm 3.1 is just the same as Algorithm 2.2. FACTORIZING WORDS OVER AN ORDERED ALPHABET 377 Thus we have that (2.1) holds and with the notation (2.4). uau=a ,. a,-,EL, a = a, and a,. . . aj-, = (uau)u. For ai ajl. Let sa be the minimum suffix of ua. Note that according to Proposition 1.13 it is the minimum suffix of (uav)?-ua which is a,. . . a,. According to Proposition 1.13 we have that minsuf( a, . . . aj,h) = minsuf(sajJz) whatever h E A*. Let k = M(i) +j - i. Since a,+, . . . a,.-, = aMCi,j+j,-i,+l . ajrpl = s, we have that minsuf(a,. ayh) = minsuf(a kf+l. a,h)whateoerh E A*. This is the justification for “k: = M(i) + j - i ” in case 3 statement. But what about the f corresponding to ak,+ , . . . aj, for the new value k of k? According to Proposition 1.12, since uau E L we have that sa is a prefix of ua. Therefore ak+ i . aj,-, = a,. . . ai,-, _ k. Then the table f is correct for a k,+l. Uj,-1, when we have it relative to the basis index k. That is truly what is done. Therefore, the process may continue and same argu- ments as above still holds. The case k = j - 1, is a particular one since we have that akT+ , . . . aj, = aj,. In such case the word reduced to a single letter is its own minimum suffix, and we process the next j. This is the justification for “if k = j - 1 then begin M(j): = k; j: = j + 1 end” in case 3 statement. THEOREM 3.1. Algorithm 3.1 computes for the word a, . . . a, the table Ml . n such that aM(j)+l aj = minsuf(a, . . . a,) (for 1 2 if there is a maximum letter c in A; otherwise P = P. We have that P c P”. Proof: Since, L c P” and each prefix of a word of P” is in P”, we have that P c P”. It is clear that for a E A and k 2 2, we have that uk E P”. Then P c P”. 0 PROPOSITION 3.2. P = P”. Proof: Let w E P” and w be the longest prefix of w which is in P. According to Proposition 1.7, we have that w has the form w = (uuv)% with u, v E A*, a E A, q 1, and uuv E L. Suppose that w f w. Let a E A, h E A*, be such that w = wah. According to Lemma 1.6, since wa 4 P we have that a ui, and k takes the new value k; for Algorithm 3.1 or k; for Algorithm 2.2. Since the process at this step consists to consider now Uk+,. a, instead of a,. . . a, with k = k, or k, k Q k, the justification of correctness is as follows: Forjgj ujt. Let su be the minimum suffix of uu. According to Proposition 1.12, su is the minimum suffix of (uuv)uu. Let tu be a suffix of (uuv)uu longer than 380 JEAN PIERRE DUVAL sa. We have that sa c ta and sa 1. It is quite clear that each circular shift of a word w is a factor of ww. Therefore, to recognize it, we may search in ww a factor of length w( which is a power of a Lyndon word. Then, the least circular shift uq of w appears when factorizing ww into Lyndon words. PROPOSITION. Let a,. a, be a word. When factorizing a,. . . anal . a, into Lyndon words by either algorithm 2.1 or algorithm 2.2, the least circular shift is ak+,. aj-, when for the first time we haue that j - 1 - k = n and j - i divides n. ProoJ: For simplification of notations we assume that a,. . . a, is a primitive word (i.e., is not a power of another word). Then, the least circular shift w = ou of a,. . . a, = uu, is a Lyndon word. We have that a,. . . anal . a, = uwo. Since u is a suffix of w, the last factor when factorizing u is a suffix of the Lyndon word w; thus it is greater than w. Since u is a prefix of w, the first factor when factorizing u is less than w. Therefore FACT (al . anal . a,) = FACT(u).w. FACT(v). Then w is a factor when factorizing a,. . . a,a, . . . a, and it

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论