서픽스 오토마톤
Suffix automaton| 서픽스 오토마톤 | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| 유형 | 서브스트링 인덱스 | ||||||||
| 발명된 | 1983 | ||||||||
| 발명자 | 앤셀름 블러머, 재닛 블러머, 안제이 에렌퓨흐트, 데이비드 하우슬러, 로스 매코넬 | ||||||||
| 빅 O 표기의 시간 복잡도 | |||||||||
| |||||||||
컴퓨터 과학에서 서픽스 오토마톤은 주어진 문자열의 서브스트링 인덱스를 나타내는 효율적인 데이터 구조이며, 모든 서브스트링에 대한 압축 정보의 저장, 처리 및 검색을 가능하게 한다.S의 접미사 오토마톤({S})은 초기 정점에서 최종 정점까지의 경로가 문자열의 접미사를 나타내도록 전용 초기 정점과 "최종" 정점 세트를 가진 최소 방향 비순환 그래프입니다.
오토마타 이론에서 접미사 오토마톤은 주어진 S 2… \ S1} 의 접미사 집합을 인식하는 최소 부분 결정론적 유한 오토마톤이다.접미사 자동화의 상태 그래프는 DAWG(Directed acyclic word graph)라고 불리며, 결정론적 비순환적 유한 상태 자동화에 사용되기도 한다.
서픽스 오토마타는 1983년 덴버 대학과 콜로라도 볼더 대학의 과학자 그룹에 의해 도입되었다.이들은 선형 시간 온라인 알고리즘을 제안했으며 길이가 최소 2자 이상인 SS})의 서픽스 오토마톤은 2개의({ 2 상태와 3개의({}) 전환이 있음을 보여주었다.추가 연구는 접미사 오토마타와 접미사 트리의 밀접한 관련성을 보여주었으며, 단일 발신 호를 가진 노드를 압축하여 얻은 압축 접미사 오토마톤과 같은 접미사 오토마타의 몇 가지 일반화를 개략적으로 설명했다.
서픽스 오토마타는 서브스트링 검색 및 2개 이상의 문자열로 이루어진 가장 큰 공통 서브스트링 계산과 같은 문제에 대한 효율적인 해결책을 제공합니다.
역사
비록 비슷한 개념 초 접미사 나무들과 함께 피터 Weiner,[2]의 작품에서 연구되어 졌다 접미사 automaton의 개념 1983[1]의 과학자들의 덴버 대학교와 콜로라도 대학교 볼더의 집단에서 안젤름 블루머, 자넷 블루머, 안제이 Ehrenfeucht, 데이비드 Haussler과 로스 매코널로 구성된 도입되었는데, Vaughan[3] 프랫과 아나톨 슬리센코.[4]Blumer 등은 초기 작업에서 길이가1({1)보다 큰 S 에 대해 작성된 접미사 오토마톤을 보여주었고 자동화에 알고리즘을 제안했다.온스트럭처링[5]
1983년 Mu-Tian Chen과 Joel Seiferas는 독자적으로 Weiner의 1973년 서픽스 트리 구축[2] 알고리즘에 문자열의서픽스 오토마톤(*S을 보조 [6]구조로 구축한다는 것을 보여주었다.1987년, Blumer 등은 접미사 트리에 사용되는 압축 기술을 접미사 오토마톤에 적용하고 압축된 접미사 오토마톤을 발명했다. 이것은 또한 CDAWG([7]compacted directed acyclic word graph)라고도 불린다.1997년 Maxime Crochemore와 Renaud Vérin은 직접 CDAWG [1]구축을 위한 선형 알고리즘을 개발했습니다.2001년, 이네나가 슌스케 등은 트라이에 [8]의해 주어진 단어 세트에 대한 CDAWG 구축 알고리즘을 개발했다.
정의들
보통 접미사 오토마타와 관련 개념에 대해 말할 때, 특히 [9]다음과 같은 형식 언어 이론과 오토마타 이론의 몇 가지 개념이 사용됩니다.
- 알파벳은 단어 구성에 사용되는 유한 집합δ(\입니다.그 요소를 '문자'라고 한다.
- "Word"는 문자 1 2 ... n { \ _ 1} \_ {2} \ \ n}。 { \ 의 "Length"는 { \=}로 됩니다.
- '포멀 랭귀지'는 주어진 알파벳 위에 있는 단어 집합이다.
- "모든 단어의 언어"는 여기서 "*" 문자는 Kleene 별을 나타냄), "빈 단어"(길이가 0인 단어)는 {\(\로 표시됩니다.
- " 연결" … n α _ { { {} 1 2 … m _ {1alpha _ {은 α \ style \ {로된다.ndsα의 에β {\로 표기하여 얻은 단어, 즉 β … m 1}\\alpha _{{{\ } \alpha } _ \lang} \alpha} \lang}{\langu}_{ \lang}_{{\
- "언어 연결" A와B(\ B는 A A B 또는 AB로 표시되며 쌍으로 연결된 { : α Adisplay B(\ AB)에 해당합니다
- 단어 \ \ in \ Sigma { * } 、 、 \ \ sigma \ alpha \ ,、 、 、、 , , \ style \ \ sigma 、 \ sigmaα α α α α α α α α α α α α α α α α α α α α α 、 \ sigma 。\displaystyle \mega 는 \ \의 "subword", "subword"(부호)로 불린다.
- \ \ } + ... \ \ T_} = 서 l{ l과 {r은 T {T에서 S {displaystyle S의 및 오른쪽 발생 위치라고 한다.
오토마톤 구조
공식적으로는 결정론적 유한 오토마톤은 5 A ( , F (\A}}=(\ Q,\delta에 의해 결정된다.[10]
- \Sigma }는 단어 구성에 사용되는 알파벳입니다.
- Q는 일련의 자동 "상태"입니다.
- 00}\ Q는 자동화의 "초기" 상태입니다.
- Q ( \ F \ Q )는 자동화의 "최종" 상태의 집합입니다.
- Q는 자동의 부분적인 "" 함수입니다.이 경우, Qσ q q display display {\ σ display display display display display q q q qq q q {\ {\ {\ {\ {\ q q {\ {\ {\ {\ {\ {\ q {\ q q {\ {\ {\ {\ {\ q q q q q q q q q q q q q q q q q q \ 。
일반적으로 결정론적 유한 오토마톤은 다음과 같이 [10]유도 그래프("그림")로 표현된다.
- 그래프 꼭지점 세트는 Q(\ Q에 대응합니다.
- 그래프에는 초기 0에 대응하는 특정 마킹된 정점이 있습니다.
- 그래프에는 최종 F F에 대응하는 여러 개의 표시된 정점이 있습니다.
- 그래프 호 세트는 트랜지션 인\에 대응합니다.
- 구체적으로는1 , ) 2 \ ( ( ( q , \ display {2는 1} )에서 로 호가 표시됩니다.이 천이는 로 될 수도 있습니다 2(\
다이어그램 측면에서, 오토마톤은 단어 1 2 … m{ \ opha _ {1}\_ { _ 을(를) 인식한다 이는 F의 초기 {\}}에서 최종 {\{0까지의 경로가 있는 에만 해당된다.path \ \ 자동으로 인식되는 단어 세트는 자동이 인식하도록 설정된 언어를 형성합니다.이 용어에서S(\ S의 접미사 오토마톤에 의해 인식되는 언어는 접미사 [9]언어(공백일 수 있음)입니다.
자동 상태
에 대한 { \ \ obega}의 "오른쪽 컨텍스트"는 집합 [] α : } { \ [ \ ] { R } = \ { \ { \ { \ \ 이며 이러한 의 이다.는 L{\ L에서 단어를 형성합니다. 오른쪽 문맥은 모든 단어 집합에서 자연스러운 동등성관계를 합니다 [ ] R [β ] { { \ ]} = [ \ ]R}L(\ L 가 어떤 결정론적 유한 오토마톤에 의해 인식되는 경우, 동일한 언어를 인식하고 가능한 최소 수의 상태를 갖는 동형 자동자까지 고유한 것이 존재합니다.이러한 자동화를 주어진 L L에 대한 최소 자동화라고 합니다. Myhill-Nerode 정리를 통해 올바른 컨텍스트의 [11][12]관점에서 명시적으로 정의할 수 있습니다.
정리 - 알파벳(\에 대한 L(\ L을 인식하는 최소 자동화는 다음과 같이 명시적으로 정의할 수 있습니다.
- 는 그대로입니다.
- Q(\ Q는 모든 한단어 에 대응합니다
- 초기 0은빈 단어[ {\R의 오른쪽 컨텍스트에 대응합니다.
- Final F { F는 Ll l from from from R의 오른쪽 컨텍스트에 대응합니다.
- ( \ \ 는 [ [ ] ]] { \ [ \} { \ {} { \ } \ \ \ \ \ [ } \ long } \ } \ {{ [ \ } { \ } { \ } { } {} { } { } { } { } { } { } { }。
이러한 용어로, "자동화"는 S …s { =}\n의 접미어 언어를 인식하는 최소 결정론적 유한 자동화이다.이 언어의 오른쪽 는{\\가 S {\ S의 접미사인α {\\alpha로 구성되어 있으며, 오른쪽 컨텍스트와 오른쪽 컨텍스트 사이의 분사를 정의하는 다음과 같은 lema를 공식화할 수 있습니다.S S[13][14]에서 발생한 올바른 위치 집합:
정리 : d s ( ) { : l { ( \ ) = \ { : \ =_ { } \ s { \} be berences of of ofof of of of theorem of of of of of of of of of of of of ofof of of of of of of of of of of of of of of of of of of of of of of of of of of of of of of
d s (" ( \ 와 [ { [ obega ] 에는 다음 분사가 있습니다.
- x e s (\ x \ ( \ ) 의 경우 + + ...s n ] [ style s + 1) s 2 \ { } \ [ \]{ } ;
- R {\alpha [ \R인 - p () \ - \\ in ( \obega )} 。
예를 들어, S {\ S와 그 서브워드 {\의 , s { 2,6} {(ab) =2, 및 b} { } r, }, a = a 、 비공식적으로 {은는) 의 끝부분까지 b(\ab가 단어로 되며, d s는 이러한 발생의 올바른 위치에 의해 형성됩니다이 예에서 x (){ x =2 \ endpos ) a[ [ ]R { { s _ { 4 }{ n ( ) s } s = { } with withrespondsrespondsrespondsrespondsrespondsrespondsrespondsrespondsrespondsrespondsrespondsrespondsrespondsresponds with in in in in in in in in은(는) 단어 a [ b ] a \ ab ]{은(는) 요소 - a d p s ( { endpos에 대응합니다
이는 접미사 자동 상태의 몇 가지 구조 속성을 의미합니다.α(\\alpha 라고 .[14]
- [ {\[\R [ R {[\R}}이 적어도1개의 공통 x {\를 가지고 경우 도 공통 요소입니다. α \alpha는β \의 이므로 (\)\(\alpha) R [] R [ displaystyle [ \ ]]의 서픽스입니다 b{ab}는 c {cab}의 서픽스이므로[ { , } [b { [ cab n s ( ) { } {, 6} n s ( )\ ( ) = \ { 6 \ } \ \ {, 6 \ } ) ;
- [β] {\ ]_{R} = [\R}인 () = ( (\ \에만 표시된다 β { \ } { , a { ] e s ( )= s ( {, 6 { endpos (b)= \ { 2 ;
- [ [ ]} [\ 및 β 의 인 경우 {\ \ \leq는 [ R의 [ ]이다.]_{ _{R}. 의에서는[] [ a ] { a b a { ]{ [ { a { [ 접미사" \ 에 해당합니다
접미사 오토마톤의 모든 q [] {\ qR}}은 이 [14]상태에서 인식되는 가장 긴 단어의 중첩된 접미사를 연속적으로 인식한다.
"왼쪽 확장" 의 displaystyle} 은(는) {\displaystyle과(와) 오른쪽 컨텍스트가 같은 가장 긴 displaystyle {style\}}}{\display 은는 [ {\q= R} 로 인식되는 가장 긴 문자열의 {\ len 로 표시됩니다.다음과 [15]같이 표시됩니다.
— {}의 왼쪽 는 β β { \ \ = \ \ {\ {\ theorem theorem theorem theorem theorem theorem theorem theorem ← theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem theorem 。
q [α ] {\ q = [\의 "Suffix link" (q {}는q {에서 인식되지 않는 α의 접미사를 포함하는 p { 에 대한 포인터입니다.
q [α ] { q [ \ ] { { { } { \ 、 l k( 또,[15] 다음과 같은 것이 있습니다.
정리 - 접미사 링크는 T 를 형성합니다.{ \{T ( 、 ) 。이러한 링크는 다음과 같이 명시적으로 정의할 수 있습니다.
- 트리의 V(\ V는 모든 S 서브스트링의 왼쪽 {\에
- 트리의 E 는 α display display over display display display display display display display display display display display display display display display display overdisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplayoverdisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplayoverdisplaydisplaydisplaydisplaydisplayoverdisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplayoverdisplaydisplayoverdisplaydisplaydisplaydisplaydisplaydisplayoveroverdisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplayover 입니다
접미사 트리를 사용한 연결
"프리픽스 트리"(또는 "트리")는 동일한 문자로 표시된 두 개의 나가는 호를 가진 vv}가 없는 방식으로 호가 문자로 표시된 루트 방향 트리입니다.trie의 일부 정점은 최종으로 표시됩니다.Trie는 어근에서 최종 꼭지점까지의 경로에 의해 정의된 단어 집합을 인식한다고 한다.이와 같이 프리픽스 트리는 루트를 초기 [16]정점으로 인식할 경우 특별한 종류의 결정론적 유한 오토마타입니다.displaystyle S)라는 단어의 "suffix trie"는 일련의 접미사를 인식하는 접두사 트리입니다."접미사 트리"는 압축절차를 통해 접미사 트리로부터 얻은 트리이며, 그 사이에 정점의 정도가 [15]2일 경우 후속 에지가 병합된다.
그 정의에 따르면 서픽스 트리e를 최소화함으로써 서픽스 오토마톤을 얻을 수 있다.접미사 트리의 최소화와(접미사 [17]트리의 가장자리에 있는 각 문자열이 알파벳의 솔리드 문자라고 가정할 경우) 접미사 오토마톤의 콤팩트화를 통해 압축된 접미사 오토마톤을 얻을 수 있음을 알 수 있다.접미사 트리와 같은 문자열의 접미사 오토마톤 간에는 이러한 연결 이외에도 S 2 … n \ S의 접미사 오토마톤과 반전 S -1 S^ 1 의 연결도 있습니다.[18]
오른쪽 컨텍스트와 마찬가지로 "왼쪽 "[ ] L { L \ [ \L } \ { \ \ in \ Sigma ^ { *} : \ \ L\ sigma \ set style 、 (\ ) {\ {\ {\styleensions {\ {\ {\ {\ωωω\ {\ωstylestylestylestyle → { \ } 및등가관계 [] [β ] { 문자열의 "" L L과 관련하여 올바른 확장자를 고려하는 경우 다음을 얻을 [15]수 있습니다.
정리 - S S의 접미사 트리는 다음과 같이 명시적으로 정의할 수 있습니다.
- 트리의 V(\ V는 S S 서브스트링의 확장 에 해당합니다.
- E(\는 x 、 x → display display display display display display display displaydisplay → display display display displaydisplay display display display display display display display display display display display display display display displaydisplaydisplay displaydisplay display display display display display display display display display display display display display display display display display display display를 클릭합니다.
여기서 triplet( 1, , )e { \ ( _ { , \ , v {} \ E}는 "{\이 표시된 1 ~2 { {}의 엣지가 있음을 의미합니다.
즉, 의 링크트리와 S의 서픽스 는 [18]동형입니다.
| 단어 "abbcbc" 및 "cbcbba"의 접미사 구조 |
|---|
왼쪽 확장의 경우와 마찬가지로 오른쪽 [15]확장의 경우 다음 보조항목이 유지됩니다.
정리 - 의 오른쪽 α displaystyle α displaystyle { } \ \ alpha로 있습니다.서는S{ \ 의 모든 발생이 성공할 수 있는 가장 긴 단어입니다.
크기
n의 S(\S의 서픽스 오토마톤에는 상태 및 의 전환이 있습니다.이러한 경계는 … b n- bb 및 b … - { bc ab^{c}에 [13]대응하여 도달합니다.이것은 Q + - 2( \ \ \+ )로 보다 엄밀하게 공식화할 수 있습니다.서 {\{ \}와 ( \ Q)는 대응하는 [14]자동화의 트랜지션 및 상태 수입니다.
| 최대 접미사 오토마타 |
|---|
건설
처음에 자동화는 빈 단어에 대응하는 단일 상태로만 구성되며, 그 후 문자열의 문자가 하나씩 추가되고 각 단계에서 자동화가 단계적으로 [19]재구축된다.
상태 갱신
문자열에 새 문자가 추가된 후 일부 동등성 클래스가 변경됩니다.[ { style [ \ { _ { \ }} { style \서픽스의 언어에 관한 의 컨텍스트라고 합니다 다음 x{\ x 에[ {에서 { x로의 천이를[14]로 정의합니다.
: ,( \ style \ alpha , \ \\ Sigma { * } some、 over over over over over over over over over over over over over displaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplaydisplay \ \ Sigma \ sigma 다음으로 [ { \ [ \ { R _ { \ obega}}과[ x { \ [\ { R { \ x 에 다음과 같은 대응이 있습니다.
- x [] R x[ { } { \ cup \ { \ α가 x { 의 접미사인
- [ x [] x [ \ \ _ \ x }=[ \ { \ obega 이외의 경우
현재 에 x 를 한 후α \의 컨텍스트는(\가 x x의 접미사인 에만 크게 변경됩니다.즉, 등가관계 R x {\displaystyle \_ x는 R { \ _ omega을 개량한 것입니다.즉 [] R [ ] R [] R \ [ \ ] X ] { \ } { \ } { \ } { } { } { } { } { } { } { } { } { } {{ [ \ ] { R _ { \ obega } = [ \ { R { \ obega}}. r 2개의 동등 클래스(\ \ { _ { \ obe } })가 추가되면 각각 최대 2개의 새로운 클래스로 분할됩니다.첫째, 빈 오른쪽 콘텍스트에 대응하는 동등성 클래스는 항상 2개의 동등성 클래스로 분할됩니다.그 중 하나는 x ( \ \x )자체에 대응하고 { ( \ \ { \ \ \ } )를 오른쪽 콘텍스트로합니다.이 새로운 등가 클래스에는 정확하게 x와에서 발생하지 않은 모든 서픽스가 포함됩니다.이러한 단어의 오른쪽 컨텍스트는 이전에는 비어 있었고 현재는 [14]빈 단어만 포함되어 있기 때문입니다.
서픽스 오토마톤 상태와 서픽스 트리의 정점과의 대응관계를 고려할 때, 새로운 문자가 부가된 후에 분할될 가능성이 있는 제2의 상태를 찾아낼 수 있다.에서 「x)」로의 이행은, 역스트링의 「})」에서 「로의 이행에 대응합니다.서픽스 트리에 관해서는 최장 R ( \ x \ { R )를R ( \ \ ^ { } )의 서픽스트리에 삽입하는 것에 대응합니다.이 삽입 후 최대 2개의 새로운 정점이 형성될 수 있습니다.x R ( x R \ x \ ^ ^ 에 합니다.나뭇가지가 있었다면 직계 조상에 해당하죠서픽스 오토마타로 돌아가면 첫 번째 새로운 상태가θ 를 하고 두 번째 상태(두 번째 새로운 상태가 있는 경우가 서픽스 링크임을 의미합니다.이는 다음과 같은 조건이라고 할 수 있다.[14]
정리 - display display display \ \ Sigma { *} , x \ x\ \ Sigma, \ \ sigma는 x 중 가장 긴 입니다. α {\ \ {\}}{\alpha그 후 모든 v 는 다음과 같이 됩니다.
- ] R [ ] { ]_인 경우및 [ [] { ]_[\ [ x [ ] x{ \ ] x x
- ] R [] { ]_인 경우}}{}} u {\ {\ 、 [] R x [ x \ [ \ x x
- ] R [] { ]_인 경우}}{R_ u> u>\ \ 다음으로 [ x [ R \ ] x x
, β { \ \display}(예를 들어 { x가 {=\ =\ 에서 전혀 발생하지 않은 )[14]는 빈 오른쪽 컨텍스트에 하는 분할된다는 것을 의미합니다
서픽스 링크 외에 오토마톤의 최종 상태를 정의하기 위해서도 필요합니다.구조 속성에서 [α {\q =]R}에 인식되는 {\displaystyle }의 모든 접미사가 접미사 경로 의 정점에 의해 인식됩니다.즉, 길이가 n ( k (){ ( (q )}{ q}}{ displaystyle ( ( )}}}{ displaystyle ( q ) stylink ( ( }}}}}보다 큰 접미사가 .) {link)} 등입니다. 를 인식하는 상태가 l {last로 표시되는 모든 최종 상태 \의 서픽스를 인식하는 상태)가 시퀀스 k ( t), 2 ( link합니다.[19]
전환 및 접미사 링크 업데이트
x(\ x가 에 추가된 후 서픽스 자동화의 새로운 상태는 [ ] x {\x] 됩니다. x및 [ x {\[\ x [ x ] R x {\ x}로부터의 서픽스 링크{ x는 [ x{\ x로 하며 [] R x {\alpha x에서 n] 로 이동한다{ x은(는) 접미사로만 {\x에만 발생하므로 [ ] R {\[\_부터의 이행은 일절 없습니다{ x은(는) 길이가α 인 {\ 의 접미사에서 시작하여 문자 {\x로 표시해야 합니다 [ R xdis {\ ] x는 의서브셋으로 됩니다.{R_ [ R x {\ x에서[ R{\ style로이행하는 것은 ] [\ ]에서와 같아야 . { \alpha} less n ( k ([ ] ) } ( link ( [ \ _ { \ obega}} ){ len ( ( [ \ alpha ]_ }) _ { \ } } } ) ωω ω ω ω ω ω ω ω ω ω ω [ {\ [이 상태의 것.이러한 서픽스에 대응하는 상태는 [ \ [ \ ] _ { \ omega[19]의 서픽스 링크 패스의 트래버설로 판별할 수 있습니다.
건설 알고리즘
상기의 이론적인 결과에 따라 x(\x)를 사용하여 자동화를 문자 x[19]의 서픽스 자동화로 재구축하는 알고리즘이 알고리즘은 다음과 같습니다.
- 에 대응하는 상태는 l \last로 됩니다.
- x x가 추가된 이전 인 t{p가 변수p last}에 되고 l t { last 가 x {\ x에 대응하는 새로운 상태로 재할당됩니다.
- 에 대응하는 상태는 \last로 하여 갱신됩니다이를 수행하려면 xx로 이미 이행한 상태가 될 때까지p , k () , 2 () , { p , ( ) , link ^ { ( ) , \ 를 해야 합니다.
- 상기의 루프가 종료하면, 다음의 3개의 케이스가 있습니다.
- 서픽스 경로 상에 x x로 이행한 상태가 없는 는 이전에 \ \omega에서 발생한 적이 없으며 에서(\ last의 서픽스 링크는로 이어집니다.
- xx에 이행이 발견되어 l (p) + n () ( \ len ( ) + 1 ( ) 에서(\q로 이어지는 경우 q {}는 분할할 필요가 없습니다
- ( )> (p )+ \ (q )p+ 1 \len + \ len ( p ) from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from from l l l l l from from from
- If the previous step was concluded with the creation of , transitions from it and its suffix link should copy those of , at the same time is assigned to be common suffix link of both and ;
- Transitions that have led to before but corresponded to words of the length at most are redirected to . To do this, one continues going through the suffix path of until the state is found such that transition by from it doesn't lead to .
The whole procedure is described by the following pseudo-code:[19]
function add_letter(x): define p = last assign last = new_state() assign len(last) = len(p) + 1 while δ(p, x) is undefined: assign δ(p, x) = last, p = link(p) define q = δ(p, x) if q = last: assign link(last) = q0 else if len(q) = len(p) + 1: assign link(last) = q else: define cl = new_state() assign len(cl) = len(p) + 1 assign δ(cl) = δ(q), link(cl) = link(q) assign link(last) = link(q) = cl while δ(p, x) = q: assign δ(p, x) = cl, p = link(p)
Here is the initial state of the automaton and is a function creating new state for it. It is assumed , , and are stored as global variables.[19]
Complexity
Complexity of the algorithm may vary depending on the underlying structure used to store transitions of the automaton. It may be implemented in with memory overhead or in with memory overhead if one assumes that memory allocation is done in . To obtain such complexity, one has to use the methods of amortized analysis. The value of strictly reduces with each iteration of the cycle while it may only increase by as much as one after the first iteration of the cycle on the next add_letter call. Overall value of never exceeds and it is only increased by one between iterations of appending new letters that suggest total complexity is at most linear as well. The linearity of the second cycle is shown in a similar way.[19]
Generalizations
The suffix automaton is closely related to other suffix structures and substring indices. Given a suffix automaton of a specific string one may construct its suffix tree via compacting and recursive traversal in linear time.[20] Similar transforms are possible in both directions to switch between the suffix automaton of and the suffix tree of reversed string .[18] Other than this several generalizations were developed to construct an automaton for the set of strings given by trie,[8] compacted suffix automation (CDAWG),[7] to maintain the structure of the automaton on the sliding window,[21] and to construct it in a bidirectional way, supporting the insertion of a characters to both the beginning and the end of the string.[22]
Compacted suffix automaton
As was already mentioned above, a compacted suffix automaton is obtained via both compaction of a regular suffix automaton (by removing states which are non-final and have exactly one out-going arc) and the minimization of a suffix tree. Similarly to the regular suffix automaton, states of compacted suffix automaton may be defined in explicit manner. A two-way extension of a word is the longest word , such that every occurrence of in is preceded by and succeeded by . In terms of left and right extensions it means that two-way extension is the left extension of the right extension or, which is equivalent, the right extension of the left extension, that is . In terms of two-way extensions compacted automaton is defined as follows:[15]
Theorem — Compacted suffix automaton of the word is defined by a pair , where:
- is a set of automaton states;
- is a set of automaton transitions.
Two-way extensions induce an equivalence relation which defines the set of words recognized by the same state of compacted automaton. This equivalence relation is a transitive closure of the relation defined by , which highlights the fact that a compacted automaton may be obtained by both gluing suffix tree vertices equivalent via relation (minimization of the suffix tree) and gluing suffix automaton states equivalent via relation (compaction of suffix automaton).[23] If words and have same right extensions, and words and have same left extensions, then cumulatively all strings , and have same two-way extensions. At the same time it may happen that neither left nor right extensions of and coincide. As an example one may take , and , for which left and right extensions are as follows: , but and . That being said, while equivalence relations of one-way extensions were formed by some continuous chain of nested prefixes or suffixes, bidirectional extensions equivalence relations are more complex and the only thing one may conclude for sure is that strings with the same two-way extension are substrings of the longest string having the same two-way extension, but it may even happen that they don't have any non-empty substring in common. The total number of equivalence classes for this relation does not exceed which implies that compacted suffix automaton of the string having length has at most states. The amount of transitions in such automaton is at most .[15]
Suffix automaton of several strings
Consider a set of words . It is possible to construct a generalization of suffix automaton that would recognize the language formed up by suffixes of all words from the set. Constraints for the number of states and transitions in such automaton would stay the same as for a single-word automaton if you put .[23] The algorithm is similar to the construction of single-word automaton except instead of state, function add_letter would work with the state corresponding to the word assuming the transition from the set of words to the set .[24][25]
This idea is further generalized to the case when is not given explicitly but instead is given by a prefix tree with vertices. Mohri et al. showed such an automaton would have at most and may be constructed in linear time from its size. At the same time, the number of transitions in such automaton may reach , for example for the set of words over the alphabet the total length of words is equal to , the number of vertices in corresponding suffix trie is equal to and corresponding suffix automaton is formed of states and transitions. Algorithm suggested by Mohri mainly repeats the generic algorithm for building automaton of several strings but instead of growing words one by one, it traverses the trie in a breadth-first search order and append new characters as it meet them in the traversal, which guarantees amortized linear complexity.[26]
Sliding window
Some compression algorithms, such as LZ77 and RLE may benefit from storing suffix automaton or similar structure not for the whole string but for only last its characters while the string is updated. This is because compressing data is usually expressively large and using memory is undesirable. In 1985, Janet Blumer developed an algorithm to maintain a suffix automaton on a sliding window of size in worst-case and on average, assuming characters are distributed independently and uniformly. She also showed complexity cannot be improved: if one considers words construed as a concatenation of several words, where , then the number of states for the window of size would frequently change with jumps of order , which renders even theoretical improvement of for regular suffix automata impossible.[27]
The same should be true for the suffix tree because its vertices correspond to states of the suffix automaton of the reversed string but this problem may be resolved by not explicitly storing every vertex corresponding to the suffix of the whole string, thus only storing vertices with at least two out-going edges. A variation of McCreight's suffix tree construction algorithm for this task was suggested in 1989 by Edward Fiala and Daniel Greene;[28] several years later a similar result was obtained with the variation of Ukkonen's algorithm by Jesper Larsson.[29][30] The existence of such an algorithm, for compacted suffix automaton that absorbs some properties of both suffix trees and suffix automata, was an open question for a long time until it was discovered by Martin Senft and Tomasz Dvorak in 2008, that it is impossible if the alphabet's size is at least two.[31]
One way to overcome this obstacle is to allow window width to vary a bit while staying . It may be achieved by an approximate algorithm suggested by Inenaga et al. in 2004. The window for which suffix automaton is built in this algorithm is not guaranteed to be of length but it is guaranteed to be at least and at most while providing linear overall complexity of the algorithm.[32]
Applications
Suffix automaton of the string may be used to solve such problems as:[33][34]
- Counting the number of distinct substrings of in on-line,
- Finding the longest substring of occurring at least twice in ,
- Finding the longest common substring of and in ,
- Counting the number of occurrences of in in ,
- Finding all occurrences of in in , where is the number of occurrences.
It is assumed here that is given on the input after suffix automaton of is constructed.[33]
Suffix automata are also used in data compression,[35] music retrieval[36][37] and matching on genome sequences.[38]
References
- ^ a b Crochemore, Vérin (1997), p. 192
- ^ a b Weiner (1973)
- ^ Pratt (1973)
- ^ Slisenko (1983)
- ^ Blumer et al. (1984), p. 109
- ^ Chen, Seiferas (1985), p. 97
- ^ a b Blumer et al. (1987), p. 578
- ^ a b Inenaga et al. (2001), p. 1
- ^ a b Crochemore, Hancart (1997), pp. 3–6
- ^ a b Серебряков и др. (2006), pp. 50–54
- ^ Рубцов (2019), pp. 89–94
- ^ Hopcroft, Ullman (1979), pp. 65–68
- ^ a b Blumer et al. (1984), pp. 111–114
- ^ a b c d e f g h Crochemore, Hancart (1997), pp. 27–31
- ^ a b c d e f g Inenaga et al. (2005), pp. 159–162
- ^ Rubinchik, Shur (2018), pp. 1–2
- ^ Inenaga et al. (2005), pp. 156–158
- ^ a b c Fujishige et al. (2016), pp. 1–3
- ^ a b c d e f g Crochemore, Hancart (1997), pp. 31–36
- ^ Паращенко (2007), pp. 19–22
- ^ Blumer (1987), p. 451
- ^ Inenaga (2003), p. 1
- ^ a b Blumer et al. (1987), pp. 585–588
- ^ Blumer et al. (1987), pp. 588–589
- ^ Blumer et al. (1987), p. 593
- ^ Mohri et al. (2009), pp. 3558–3560
- ^ Blumer (1987), pp. 461–465
- ^ Fiala, Greene (1989), p. 490
- ^ Larsson (1996)
- ^ Brodnik, Jekovec (2018), p. 1
- ^ Senft, Dvořák (2008), p. 109
- ^ Inenaga et al. (2004)
- ^ a b Crochemore, Hancart (1997), pp. 36–39
- ^ Crochemore, Hancart (1997), pp. 39–41
- ^ Yamamoto et al. (2014), p. 675
- ^ Crochemore et al. (2003), p. 211
- ^ Mohri et al. (2009), p. 3553
- ^ Faro (2016), p. 145
Bibliography
- Anselm Cyril Blumer; Janet Blumer; Andrzej Ehrenfeucht; David Haussler; Ross McConnell (1984). Building the minimal DFA for the set of all subwords of a word on-line in linear time. International Colloquium on Automata, Languages and Programming. pp. 109–118. doi:10.1007/3-540-13345-3_9. ISBN 978-3-540-13345-2. Wikidata Q90309073.
- Anselm Cyril Blumer; Janet Blumer; Andrzej Ehrenfeucht; David Haussler; Ross McConnell (July 1987). "Complete inverted files for efficient text retrieval and analysis". Journal of the ACM. 34 (3): 578–595. CiteSeerX 10.1.1.87.6824. doi:10.1145/28869.28873. ISSN 0004-5411. Wikidata Q90311855.
- Janet Blumer (December 1987). "How much is that DAWG in the window? A moving window algorithm for the directed acyclic word graph". Journal of Algorithms. 8 (4): 451–469. doi:10.1016/0196-6774(87)90045-9. ISSN 0196-6774. Wikidata Q90327976.
- Andrej Brodnik; Matevž Jekovec (3 August 2018). "Sliding Suffix Tree". Algorithms. 11 (8): 118. doi:10.3390/A11080118. ISSN 1999-4893. Wikidata Q90431196.
- Mu-Tian Chen; Joel Seiferas (1985). Efficient and Elegant Subword-Tree Construction. Combinatorial Algorithms on Words. pp. 97–107. CiteSeerX 10.1.1.632.4. doi:10.1007/978-3-642-82456-2_7. ISBN 978-3-642-82456-2. Wikidata Q90329833.
- Maxime Crochemore; Christophe Hancart (1997). Automata for Matching Patterns. Handbook of Formal Languages. Vol. 2. pp. 399–462. CiteSeerX 10.1.1.392.8637. doi:10.1007/978-3-662-07675-0_9. ISBN 978-3-642-59136-5. Wikidata Q90413384.
- Maxime Crochemore; Renaud Vérin (1997). On compact directed acyclic word graphs. Structures in Logic and Computer Science. Lecture Notes in Computer Science. pp. 192–211. CiteSeerX 10.1.1.13.6892. doi:10.1007/3-540-63246-8_12. ISBN 978-3-540-69242-3. Wikidata Q90413885.
- Maxime Crochemore; Costas S. Iliopoulos; Gonzalo Navarro; Yoan J. Pinzon (2003). A Bit-Parallel Suffix Automaton Approach for (δ,γ)-Matching in Music Retrieval. International Symposium on String Processing and Information Retrieval. pp. 211–223. CiteSeerX 10.1.1.8.533. doi:10.1007/978-3-540-39984-1_16. ISBN 978-3-540-39984-1. Wikidata Q90414195.
- Vladimir Serebryakov; Maksim Pavlovich Galochkin; Meran Gabibullaevich Furugian; Dmitriy Ruslanovich Gonchar (2006). Теория и реализация языков программирования: Учебное пособие (PDF) (in Russian). Moscow: MZ Press. ISBN 5-94073-094-9. Wikidata Q90432456.
- Simone Faro (2016). Evaluation and Improvement of Fast Algorithms for Exact Matching on Genome Sequences. International Conference on Algorithms for Computational Biology. Lecture Notes in Computer Science. pp. 145–157. doi:10.1007/978-3-319-38827-4_12. ISBN 978-3-319-38827-4. Wikidata Q90412338.
- Edward R. Fiala; Daniel H. Greene (April 1989). "Data compression with finite windows". Communications of the ACM. 32 (4): 490–505. doi:10.1145/63334.63341. ISSN 0001-0782. Wikidata Q90425560.
- Yuta Fujishige; Yuki Tsujimaru; Shunsuke Inenaga; Hideo Bannai; Masayuki Takeda (2016). Computing DAWGs and Minimal Absent Words in Linear Time for Integer Alphabets (PDF). International Symposium on Mathematical Foundations of Computer Science. Vol. 58. pp. 38:1–38:14. doi:10.4230/LIPICS.MFCS.2016.38. ISBN 978-3-95977-016-3. ISSN 1868-8969. Wikidata Q90410044.
- John Edward Hopcroft; Jeffrey David Ullman (1979). Introduction to Automata Theory, Languages, and Computation (1st ed.). Massachusetts: Addison-Wesley. ISBN 978-81-7808-347-6. OL 9082218M. Wikidata Q90418603.
- Shunsuke Inenaga (March 2003). "Bidirectional Construction of Suffix Trees" (PDF). Nordic Journal of Computing. 10 (1): 52–67. CiteSeerX 10.1.1.100.8726. ISSN 1236-6064. Wikidata Q90335534.
- Shunsuke Inenaga; Hiromasa Hoshino; Ayumi Shinohara; Masayuki Takeda; Setsuo Arikawa; Giancarlo Mauri; Giulio Pavesi (March 2005). "On-line construction of compact directed acyclic word graphs". Discrete Applied Mathematics. 146 (2): 156–179. CiteSeerX 10.1.1.1039.6992. doi:10.1016/J.DAM.2004.04.012. ISSN 0166-218X. Wikidata Q57518591.
- Shunsuke Inenaga; Hiromasa Hoshino; Ayumi Shinohara; Masayuki Takeda; Setsuo Arikawa (2001). "Construction of the CDAWG for a trie" (PDF). Prague Stringology Conference. Proceedings: 37–48. CiteSeerX 10.1.1.24.2637. Wikidata Q90341606.
- Shunsuke Inenaga; Ayumi Shinohara; Masayuki Takeda; Setsuo Arikawa (March 2004). "Compact directed acyclic word graphs for a sliding window". Journal of Discrete Algorithms. 2 (1): 33–51. CiteSeerX 10.1.1.101.358. doi:10.1016/S1570-8667(03)00064-9. ISSN 1570-8667. Wikidata Q90345535.
- N. Jesper Larsson (1996). "Extended application of suffix trees to data compression". Proceedings. Data Compression Conference: 190–199. CiteSeerX 10.1.1.12.8623. doi:10.1109/DCC.1996.488324. ISSN 2375-0383. Wikidata Q90427112.
- Mehryar Mohri; Pedro Moreno; Eugene Weinstein (September 2009). "General suffix automaton construction algorithm and space bounds". Theoretical Computer Science. 410 (37): 3553–3562. CiteSeerX 10.1.1.157.7443. doi:10.1016/J.TCS.2009.03.034. ISSN 0304-3975. Wikidata Q90410808.
- Дмитрий А. Паращенко (2007), Обработка строк на основе суффиксных автоматов (PDF) (in Russian), Saint Petersburg: ITMO University, Wikidata Q90436837
- Vaughan Ronald Pratt (1973), Improvements and applications for the Weiner repetition finder, OCLC 726598262, Wikidata Q90300966
- Александр Александрович Рубцов (2019). Заметки и задачи о регулярных языках и конечных автоматах (PDF) (in Russian). Moscow: Moscow Institute of Physics and Technology. ISBN 978-5-7417-0702-9. Wikidata Q90435728.
- Mikhail Rubinchik; Arseny M. Shur (February 2018). "Eertree: An efficient data structure for processing palindromes in strings" (PDF). European Journal of Combinatorics. 68: 249–265. arXiv:1506.04862. doi:10.1016/J.EJC.2017.07.021. ISSN 0195-6698. Wikidata Q90726647.
- Martin Senft; Tomáš Dvořák (2008). Sliding CDAWG Perfection. International Symposium on String Processing and Information Retrieval. pp. 109–120. doi:10.1007/978-3-540-89097-3_12. ISBN 978-3-540-89097-3. Wikidata Q90426624.
- Anatoly Olesievich Slisenko (1983). "Detection of periodicities and string-matching in real time". Journal of Mathematical Sciences. 22 (3): 1316–1387. doi:10.1007/BF01084395. ISSN 1072-3374. Wikidata Q90305414.
- Peter Weiner (October 1973). "Linear pattern matching algorithms". Symposium on Foundations of Computer Science: 1–11. CiteSeerX 10.1.1.474.9582. doi:10.1109/SWAT.1973.13. Wikidata Q29541479.
- Jun'ichi Yamamoto; Tomohiro I; Hideo Bannai; Shunsuke Inenaga; Masayuki Takeda (2014). Faster Compact On-Line Lempel-Ziv Factorization (PDF). Symposium on Theoretical Aspects of Computer Science. Leibniz International Proceedings in Informatics. Vol. 25. pp. 675–686. CiteSeerX 10.1.1.742.6691. doi:10.4230/LIPICS.STACS.2014.675. ISBN 978-3-939897-65-1. ISSN 1868-8969. Wikidata Q90348192.
External links
Media related to Suffix automaton at Wikimedia Commons- Suffix automaton article on E-Maxx Algorithms in English