Suffix automaton

Short description: Deterministic finite automaton accepting set of all suffixes of particular string

Suffix automaton

Type| Substring index
Invented| 1983
Invented by| Anselm Blumer; Janet Blumer; Andrzej Ehrenfeucht; David Haussler; Ross McConnell
Time complexity in big O notation
| Algorithm|  |  Average|  Worst case

|
|
|

Space|  |  O(n)|  O(n)

In computer science, a suffix automaton is an efficient data structure for representing the substring index of a given string which allows the storage, processing, and retrieval of compressed information about all its substrings. The suffix automaton of a string S is the smallest directed acyclic graph with a dedicated initial vertex and a set of "final" vertices, such that paths from the initial vertex to final vertices represent the suffixes of the string.

In terms of automata theory, a suffix automaton is the minimal partial deterministic finite automaton that recognizes the set of suffixes of a given string S=s1s2…sn. The state graph of a suffix automaton is called a directed acyclic word graph (DAWG), a term that is also sometimes used for any deterministic acyclic finite state automaton.

Suffix automata were introduced in 1983 by a group of scientists from the University of Denver and the University of Colorado Boulder. They suggested a linear time online algorithm for its construction and showed that the suffix automaton of a string S having length at least two characters has at most 2|S|−1 states and at most 3|S|−4 transitions. Further works have shown a close connection between suffix automata and suffix trees, and have outlined several generalizations of suffix automata, such as compacted suffix automaton obtained by compression of nodes with a single outgoing arc.

Suffix automata provide efficient solutions to problems such as substring search and computation of the largest common substring of two and more strings.

## Contents

* 1 History
* 2 Definitions
* 3 Automaton structure
* 3.1 Automaton states
* 3.2 Connection with suffix trees
* 3.3 Size
* 4 Construction
* 4.1 State updates
* 4.2 Transitions and suffix links updates
* 4.3 Construction algorithm
* 4.4 Complexity
* 5 Generalizations
* 5.1 Compacted suffix automaton
* 5.2 Suffix automaton of several strings
* 5.3 Sliding window
* 6 Applications
* 7 References
* 7.1 Bibliography
* 8 External links

## History

Anselm Blumer with a drawing of generalized CDAWG for strings ababc and abcab

The concept of suffix automaton was introduced in 1983[1] by a group of scientists from University of Denver and University of Colorado Boulder consisting of Anselm Blumer, Janet Blumer, Andrzej Ehrenfeucht, David Haussler and Ross McConnell, although similar concepts had earlier been studied alongside suffix trees in the works of Peter Weiner,[2] Vaughan Pratt[3] and Anatol Slissenko.[4] In their initial work, Blumer et al. showed a suffix automaton built for the string S of length greater than 1 has at most 2|S|−1 states and at most 3|S|−4 transitions, and suggested a linear algorithm for automaton construction.[5]

In 1983, Mu-Tian Chen and Joel Seiferas independently showed that Weiner's 1973 suffix-tree construction algorithm[2] while building a suffix tree of the string S constructs a suffix automaton of the reversed string SR as an auxiliary structure.[6] In 1987, Blumer et al. applied the compressing technique used in suffix trees to a suffix automaton and invented the compacted suffix automaton, which is also called the compacted directed acyclic word graph (CDAWG).[7] In 1997, Maxime Crochemore and Renaud Vérin developed a linear algorithm for direct CDAWG construction.[1] In 2001, Shunsuke Inenaga et al. developed an algorithm for construction of CDAWG for a set of words given by a trie.[8]

## Definitions

Usually when speaking about suffix automata and related concepts, some notions from formal language theory and automata theory are used, in particular:[9]

* "Alphabet" is a finite set Σ that is used to construct words. Its elements are called "characters";
* "Word" is a finite sequence of characters ω=ω1ω2…ωn. "Length" of the word ω is denoted as |ω|=n;
* "Formal language" is a set of words over given alphabet;
* "Language of all words" is denoted as Σ*(where the "*" character stands for Kleene star), "empty word" (the word of zero length) is denoted by the character ε;
* "Concatenation of words" α=α1α2…αn and β=β1β2…βm is denoted as α⋅β or αβ and corresponds to the word obtained by writing β to the right of α, that is, αβ=α1α2…αnβ1β2…βm;
* "Concatenation of languages" A and B is denoted as A⋅B or AB and corresponds to the set of pairwise concatenations AB={αβ:α∈A,β∈B};
* If the word ω∈Σ* may be represented as ω=αγβ, where α,β,γ∈Σ*, then words α, β and γ are called "prefix", "suffix" and "subword" (substring) of the word ω correspondingly;
* If T=T1…Tn and TlTl+1…Tr=S (with 1≤l≤r≤n) then S is said to "occur" in T as a subword. Here l and r are called left and right positions of occurrence of S in T correspondingly.

## Automaton structure

Formally, deterministic finite automaton is determined by 5-tuple 𝒜=(Σ,Q,q0,F,δ), where:[10]

* Σ is an "alphabet" that is used to construct words,
* Q is a set of automaton "states",
* q0∈Q is an "initial" state of automaton,
* F⊂Q is a set of "final" states of automaton,
* δ:Q×Σ↦Q is a partial "transition" function of automaton, such that δ(q,σ) for q∈Q and σ∈Σ is either undefined or defines a transition from q over character σ.

Most commonly, deterministic finite automaton is represented as a directed graph ("diagram") such that:[10]

* Set of graph vertices corresponds to the state of states Q,
* Graph has a specific marked vertex corresponding to initial state q0,
* Graph has several marked vertices corresponding to the set of final states F,
* Set of graph arcs corresponds to the set of transitions δ,
* Specifically, every transition δ(q1,σ)=q2 is represented by an arc from q1 to q2 marked with the character σ. This transition also may be denoted as q1σ⟶q2.

In terms of its diagram, the automaton recognizes the word ω=ω1ω2…ωm only if there is a path from the initial vertex q0 to some final vertex q∈F such that concatenation of characters on this path forms ω. The set of words recognized by an automaton forms a language that is set to be recognized by the automaton. In these terms, the language recognized by a suffix automaton of S is the language of its (possibly empty) suffixes.[9]

### Automaton states

Main article: DFA minimization

"Right context" of the word ω with respect to language L is a set [ω]R={α:ωα∈L} that is a set of words α such that their concatenation with ω forms a word from L. Right contexts induce a natural equivalence relation [α]R=[β]R on the set of all words. If language L is recognized by some deterministic finite automaton, there exists unique up to isomorphism automaton that recognizes the same language and has the minimum possible number of states. Such an automaton is called a minimal automaton for the given language L. Myhill–Nerode theorem allows it to define it explicitly in terms of right contexts:[11][12]

Theorem -- Minimal automaton recognizing language L over the alphabet Σ may be explicitly defined in the following way:

* Alphabet Σ stays the same,
* States Q correspond to right contexts [ω]R of all possible words ω∈Σ*,
* Initial state q0 corresponds to the right context of the empty word [ε]R,
* Final states F correspond to right contexts [ω]R of words from ω∈L,
* Transitions δ are given by [ω]Rσ⟶[ωσ]R, where ω∈Σ* and σ∈Σ.

In these terms, a "suffix automaton" is the minimal deterministic finite automaton recognizing the language of suffixes of the word S=s1s2…sn. The right context of the word ω with respect to this language consists of words α, such that ωα is a suffix of S. It allows to formulate the following lemma defining a bijection between the right context of the word and the set of right positions of its occurrences in S:[13][14]

Theorem -- Let endpos(ω)={r:ω=sl…sr} be the set of right positions of occurrences of ω in S.

There is a following bijection between endpos(ω) and [ω]R:

* If x∈endpos(ω), then sx+1sx+2…sn∈[ω]R;
* If α∈[ω]R, then n−|α|∈endpos(ω).

For example, for the word S=abacaba and its subword ω=ab, it holds endpos(ab)={2,6} and [ab]R={a,acaba}. Informally, [ab]R is formed by words that follow occurrences of ab to the end of S and endpos(ab) is formed by right positions of those occurrences. In this example, the element x=2∈endpos(ab) corresponds with the word s3s4s5s6s7=acaba∈[ab]R while the word a∈[ab]R corresponds with the element 7−|a|=6∈endpos(ab).

It implies several structure properties of suffix automaton states. Let |α|≤|β|, then:[14]

* If [α]R and [β]R have at least one common element x, then endpos(α) and endpos(β) have a common element as well. It implies α is a suffix of β and therefore endpos(β)⊂endpos(α) and [β]R⊂[α]R. In aforementioned example, a∈[ab]R∩[cab]R, so ab is a suffix of cab and thus [cab]R={a}⊂{a,acaba}=[ab]R and endpos(cab)={6}⊂{2,6}=endpos(ab);
* If [α]R=[β]R, then endpos(α)=endpos(β), thus α occurs in S only as a suffix of β. For example, for α=b and β=ab it holds that [b]R=[ab]R={a,acaba} and endpos(b)=endpos(ab)={2,6};
* If [α]R=[β]R and γ is a suffix of β such that |α|≤|γ|≤|β|, then [α]R=[γ]R=[β]R. In the example above [c]R=[bac]R={aba} and it holds for "intermediate" suffix γ=ac that [ac]R={aba}.

Any state q=[α]R of the suffix automaton recognizes some continuous chain of nested suffixes of the longest word recognized by this state.[14]

"Left extension" γ<- of the string γ is the longest string ω that has the same right context as γ. Length |γ<-| of the longest string recognized by q=[γ]R is denoted by len(q). It holds:[15]

Theorem -- Left extension of γ may be represented as γ<-=βγ, where β is the longest word such that any occurrence of γ in S is preceded by β.

"Suffix link" link(q) of the state q=[α]R is the pointer to the state p that contains the largest suffix of α that is not recognized by q.

In this terms it can be said q=[α]R recognizes exactly all suffixes of α<- that is longer than len(link(q)) and not longer than len(q). It also holds:[15]

Theorem -- Suffix links form a tree 𝒯(V,E) that may be defined explicitly in the following way:

1. Vertices V of the tree correspond to left extensions ω<- of all S substrings,
2. Edges E of the tree connect pairs of vertices (ω<-,αω<-), such that α∈Σ and ω<-≠αω<-.

### Connection with suffix trees

Relationship of the suffix trie, suffix tree, DAWG and CDAWG

Main article: Suffix tree

A "prefix tree" (or "trie") is a rooted directed tree in which arcs are marked by characters in such a way no vertex v of such tree has two out-going arcs marked with the same character. Some vertices in trie are marked as final. Trie is said to recognize a set of words defined by paths from its root to final vertices. In this way prefix trees are a special kind of deterministic finite automata if you perceive its root as an initial vertex.[16] The "suffix trie" of the word S is a prefix tree recognizing a set of its suffixes. "A suffix tree" is a tree obtained from a suffix trie via the compaction procedure, during which consequent edges are merged if the degree of the vertex between them is equal to two.[15]

By its definition, a suffix automaton can be obtained via minimization of the suffix trie. It may be shown that a compacted suffix automaton is obtained by both minimization of the suffix tree (if one assumes each string on the edge of the suffix tree is a solid character from the alphabet) and compaction of the suffix automaton.[17] Besides this connection between the suffix tree and the suffix automaton of the same string there is as well a connection between the suffix automaton of the string S=s1s2…sn and the suffix tree of the reversed string SR=snsn−1…s1.[18]

Similarly to right contexts one may introduce "left contexts" [ω]L={β∈Σ*:βω∈L}, "right extensions" ω-> corresponding to the longest string having same left context as ω and the equivalence relation [α]L=[β]L. If one considers right extensions with respect to the language L of "prefixes" of the string S it may be obtained:[15]

Theorem -- Suffix tree of the string S may be defined explicitly in the following way:

* Vertices V of the tree correspond to right extensions ω-> of all S substrings,
* Edges E correspond to triplets (ω->,xα,ωx->) such that x∈Σ and ωx->=ω->xα.

Here triplet (v1,ω,v2)∈E means there is an edge from v1 to v2 with the string ω written on it

, which implies the suffix link tree of the string

and the suffix tree of the string

are isomorphic:[18]

Suffix structures of words "abbcbc" and "cbcbba"

* Suffix automaton of the word "abbcbc"

* Suffix trie, suffix tree and CDAWG of the word "abbcbc"

* Suffix tree of the word "cbcbba"
(Suffix link tree of the word "abbcbc")

Similarly to the case of left extensions, the following lemma holds for right extensions:[15]

Theorem -- Right extension of the string γ may be represented as γ->=γα, where α is the longest word such that every occurrence of γ in S is succeeded by α.

### Size

A suffix automaton of the string S of length n>1 has at most 2n−1 states and at most 3n−4 transitions. These bounds are reached on strings abb…bb=abn−1 and abb…bc=abn−2c correspondingly.[13] This may be formulated in a stricter way as |δ|≤|Q|+n−2 where |δ| and |Q| are the numbers of transitions and states in automaton correspondingly.[14]

Maximal suffix automata

* Suffix automaton of abn−1

* Suffix automaton of abn−2c

## Construction

Initially the automaton only consists of a single state corresponding to the empty word, then characters of the string are added one by one and the automaton is rebuilt on each step incrementally.[19]

### State updates

After a new character is appended to the string, some equivalence classes are altered. Let [α]Rω be the right context of α with respect to the language of ω suffixes. Then the transition from [α]Rω to [α]Rωx after x is appended to ω is defined by lemma:[14]

Theorem -- Let α,ω∈Σ* be some words over Σ and x∈Σ be some character from this alphabet. Then there is a following correspondence between [α]Rω and [α]Rωx:

* [α]Rωx=[α]Rωx∪{ε} if α is a suffix of ωx;
* [α]Rωx=[α]Rωx otherwise.

After adding x to the current word ω the right context of α may change significantly only if α is a suffix of ωx. It implies equivalence relation ≡Rωx is a refinement of ≡Rω. In other words, if [α]Rωx=[β]Rωx, then [α]Rω=[β]Rω. After the addition of a new character at most two equivalence classes of ≡Rω will be split and each of them may split in at most two new classes. First, equivalence class corresponding to empty right context is always split into two equivalence classes, one of them corresponding to ωx itself and having {ε} as a right context. This new equivalence class contains exactly ωx and all its suffixes that did not occur in ω, as the right context of such words was empty before and contains only empty word now.[14]

Given the correspondence between states of the suffix automaton and vertices of the suffix tree, it is possible to find out the second state that may possibly split after a new character is appended. The transition from ω to ωx corresponds to the transition from ωR to xωR in the reversed string. In terms of suffix trees it corresponds to the insertion of the new longest suffix xωR into the suffix tree of ωR. At most two new vertices may be formed after this insertion: one of them corresponding to xωR, while the other one corresponds to its direct ancestor if there was a branching. Returning to suffix automata, it means the first new state recognizes ωx and the second one (if there is a second new state) is its suffix link. It may be stated as a lemma:[14]

Theorem -- Let ω∈Σ*, x∈Σ be some word and character over Σ. Also let α be the longest suffix of ωx, which occurs in ω, and let β=α<-. Then for any substrings u,v of ω it holds:

* If [u]Rω=[v]Rω and [u]Rω≠[α]Rω, then [u]Rωx=[v]Rωx;
* If [u]Rω=[α]Rω and |u|≤|α|, then [u]Rωx=[α]Rωx;
* If [u]Rω=[α]Rω and |u|>|α|, then [u]Rωx=[β]Rωx.

It implies that if α=β (for example, when x didn't occur in ω at all and α=β=ε), then only the equivalence class corresponding to the empty right context is split.[14]

Besides suffix links it is also needed to define final states of the automaton. It follows from structure properties that all suffixes of a word α recognized by q=[α]R are recognized by some vertex on suffix path (q,link(q),link2(q),…) of q. Namely, suffixes with length greater than len(link(q)) lie in q, suffixes with length greater than len(link(link(q)) but not greater than len(link(q)) lie in link(q) and so on. Thus if the state recognizing ω is denoted by last, then all final states (that is, recognizing suffixes of ω) form up the sequence (last,link(last),link2(last),…).[19]

### Transitions and suffix links updates

After the character x is appended to ω possible new states of suffix automaton are [ωx]Rωx and [α]Rωx. Suffix link from [ωx]Rωx goes to [α]Rωx and from [α]Rωx it goes to link([α]Rω). Words from [ωx]Rωx occur in ωx only as its suffixes therefore there should be no transitions at all from [ωx]Rωx while transitions to it should go from suffixes of ω having length at least α and be marked with the character x. State [α]Rωx is formed by subset of [α]Rω, thus transitions from [α]Rωx should be same as from [α]Rω. Meanwhile, transitions leading to [α]Rωx should go from suffixes of ω having length less than |α| and at least len(link([α]Rω)), as such transitions have led to [α]Rω before and corresponded to seceded part of this state. States corresponding to these suffixes may be determined via traversal of suffix link path for [ω]Rω.[19]

Construction of the suffix automaton for the word abbcbc

∅ → a | 280x150px  | 280x150px

|

After first character is appended, only one state is created in suffix automaton. | Similarly, only one leaf is added to the suffix tree.
a → ab | 280x150px  | 280x150px

|

New transitions are drawn from all previous final states as b didn't appear before. | For the same reason another leaf is added to the root of the suffix tree.
ab → abb | 280x180px  | 280x180px

|

The state 2 recognizes words ab and b, but only b is the new suffix, therefore this word is separated into state 4. | In the suffix tree it corresponds to the split of the edge leading to the vertex 2.
abb → abbc | 280x180px  | 280x180px

|

Character c occurs for the first time, so transitions are drawn from all previous final states. | Suffix tree of reverse string has another leaf added to the root.
abbc → abbcb | 280x210px  | 280x210px

|

State 4 consists of the only word b, which is suffix, thus the state is not split. | Correspondingly, new leaf is hanged on the vertex 4 in the suffix tree.
abbcb → abbcbc | 280x210px  | 280x210px

|

The state 5 recognizes words abbc, bbc, bc and c, but only last two are suffixes of new word, so they're separated into new state 8. | Correspondingly, edge leading to the vertex 5 is split and vertex 8 is put in the middle of the edge.

### Construction algorithm

Theoretical results above lead to the following algorithm that takes character x and rebuilds the suffix automaton of ω into the suffix automaton of ωx:[19]

1. The state corresponding to the word ω is kept as last;
2. After x is appended, previous value of last is stored in the variable p and last itself is reassigned to the new state corresponding to ωx;
3. States corresponding to suffixes of ω are updated with transitions to last. To do this one should go through p,link(p),link2(p),…, until there is a state that already has a transition by x;
4. Once the aforementioned loop is over, there are 3 cases:
1. If none of states on the suffix path had a transition by x, then x never occurred in ω before and the suffix link from last should lead to q0;
2. If the transition by x is found and leads from the state p to the state q, such that len(p)+1=len(q), then q does not have to be split and it is a suffix link of last;
3. If the transition is found but len(q)>len(p)+1, then words from q having length at most len(p)+1 should be segregated into new "clone" state cl;
5. If the previous step was concluded with the creation of cl, transitions from it and its suffix link should copy those of q, at the same time cl is assigned to be common suffix link of both q and last;
6. Transitions that have led to q before but corresponded to words of the length at most len(p)+1 are redirected to cl. To do this, one continues going through the suffix path of p until the state is found such that transition by x from it doesn't lead to q.

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 q0 is the initial state of the automaton and `new_state()` is a function creating new state for it. It is assumed `last`, `len`, `link` and `δ` are stored as global variables.[19] For convenience, `link(q0)` is defined to be q0.

### Complexity

Complexity of the algorithm may vary depending on the underlying structure used to store transitions of the automaton. It may be implemented in O(nlog⁡|Σ|) with O(n) memory overhead or in O(n) with O(n|Σ|) memory overhead if one assumes that memory allocation is done in O(1). To obtain such complexity, one has to use the methods of amortized analysis. The value of len(p) 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 len(p) never exceeds n 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 S and the suffix tree of reversed string SR.[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 S 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 S is defined by a pair (V,E), where:

* V={ω↔:ω∈Σ*} is a set of automaton states;
* E={(ω↔,xα,ωx↔):x∈Σ,α∈Σ*,ωx↔=ω↔xα} 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 S=β=ab, α=a and γ=b, for which left and right extensions are as follows: α->=β->=ab=β<-=γ<-, but γ->=b and α<-=a. 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 n+1 which implies that compacted suffix automaton of the string having length n has at most n+1 states. The amount of transitions in such automaton is at most 2n−2.[15]

### Suffix automaton of several strings

Consider a set of words T={S1,S2,…,Sk}. 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 n=|S1|+|S2|+…+|Sk|.[23] The algorithm is similar to the construction of single-word automaton except instead of last state, function add_letter would work with the state corresponding to the word ωi assuming the transition from the set of words {ω1,…,ωi,…,ωk} to the set {ω1,…,ωix,…,ωk}.[24][25]

This idea is further generalized to the case when T is not given explicitly but instead is given by a prefix tree with Q vertices. Mohri et al. showed such an automaton would have at most 2Q−2 and may be constructed in linear time from its size. At the same time, the number of transitions in such automaton may reach O(Q|Σ|), for example for the set of words T={σ1,aσ1,a2σ1,…,anσ1,anσ2,…,anσk} over the alphabet Σ={a,σ1,…,σk} the total length of words is equal to O(n2+nk), the number of vertices in corresponding suffix trie is equal to O(n+k) and corresponding suffix automaton is formed of O(n+k) states and O(nk) 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 k its characters while the string is updated. This is because compressing data is usually expressively large and using O(n) memory is undesirable. In 1985, Janet Blumer developed an algorithm to maintain a suffix automaton on a sliding window of size k in O(nk) worst-case and O(nlog⁡k) on average, assuming characters are distributed independently and uniformly. She also showed O(nk) complexity cannot be improved: if one considers words construed as a concatenation of several (ab)mc(ab)md words, where k=6m+2, then the number of states for the window of size k would frequently change with jumps of order m, which renders even theoretical improvement of O(nk) 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 O(k). 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 k but it is guaranteed to be at least k and at most 2k+1 while providing linear overall complexity of the algorithm.[32]

## Applications

Suffix automaton of the string S may be used to solve such problems as:[33][34]

* Counting the number of distinct substrings of S in O(|S|) on-line,
* Finding the longest substring of S occurring at least twice in O(|S|),
* Finding the longest common substring of S and T in O(|T|),
* Counting the number of occurrences of T in S in O(|T|),
* Finding all occurrences of T in S in O(|T|+k), where k is the number of occurrences.

It is assumed here that T is given on the input after suffix automaton of S is constructed.[33]

Suffix automata are also used in data compression,[35] music retrieval[36][37] and matching on genome sequences.[38]

## References

1. ↑ 1.0 1.1 Crochemore & Vérin (1997), p. 192
2. ↑ 2.0 2.1 Weiner (1973)
3. ↑ Pratt (1973)
4. ↑ Slisenko (1983)
5. ↑ Blumer et al. (1984), p. 109
6. ↑ Chen & Seiferas (1985), p. 97
7. ↑ 7.0 7.1 Blumer et al. (1987), p. 578
8. ↑ 8.0 8.1 Inenaga et al. (2001), p. 1
9. ↑ 9.0 9.1 Crochemore & Hancart (1997), pp. 3–6
10. ↑ 10.0 10.1 Serebryakov et al. (2006), pp. 50–54
11. ↑ Рубцов (2019), pp. 89–94
12. ↑ Hopcroft & Ullman (1979), pp. 65–68
13. ↑ 13.0 13.1 Blumer et al. (1984), pp. 111–114
14. ↑ 14.0 14.1 14.2 14.3 14.4 14.5 14.6 14.7 Crochemore & Hancart (1997), pp. 27–31
15. ↑ 15.0 15.1 15.2 15.3 15.4 15.5 15.6 Inenaga et al. (2005), pp. 159–162
16. ↑ Rubinchik & Shur (2018), pp. 1–2
17. ↑ Inenaga et al. (2005), pp. 156–158
18. ↑ 18.0 18.1 18.2 Fujishige et al. (2016), pp. 1–3
19. ↑ 19.0 19.1 19.2 19.3 19.4 19.5 19.6 Crochemore & Hancart (1997), pp. 31–36
20. ↑ Паращенко (2007), pp. 19–22
21. ↑ Blumer (1987), p. 451
22. ↑ Inenaga (2003), p. 1
23. ↑ 23.0 23.1 Blumer et al. (1987), pp. 585–588
24. ↑ Blumer et al. (1987), pp. 588–589
25. ↑ Blumer et al. (1987), p. 593
26. ↑ Mohri, Moreno & Weinstein (2009), pp. 3558–3560
27. ↑ Blumer (1987), pp. 461–465
28. ↑ Fiala & Greene (1989), p. 490
29. ↑ Larsson (1996)
30. ↑ Brodnik & Jekovec (2018), p. 1
31. ↑ Senft & Dvořák (2008), p. 109
32. ↑ Inenaga et al. (2004)
33. ↑ 33.0 33.1 Crochemore & Hancart (1997), pp. 36–39
34. ↑ Crochemore & Hancart (1997), pp. 39–41
35. ↑ Yamamoto et al. (2014), p. 675
36. ↑ Crochemore et al. (2003), p. 211
37. ↑ Mohri, Moreno & Weinstein (2009), p. 3553
38. ↑ Faro (2016), p. 145

### Bibliography

* Blumer, A.; Blumer, J.; Ehrenfeucht, A.; Haussler, D.; McConnell, R. (1984). "Building the minimal DFA for the set of all subwords of a word on-line in linear time". Automata, Languages and Programming. Lecture Notes in Computer Science. 172. pp. 109–118. doi:10.1007/3-540-13345-3_9. ISBN 978-3-540-13345-2.
* Blumer, A.; Blumer, J.; Haussler, D.; McConnell, R.; Ehrenfeucht, A. (1987). "Complete inverted files for efficient text retrieval and analysis". Journal of the ACM 34 (3): 578–595. doi:10.1145/28869.28873.
* Blumer, Janet A. (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.
* Brodnik, Andrej; Jekovec, Matevž (2018). "Sliding Suffix Tree". Algorithms 11 (8): 118. doi:10.3390/A11080118.
* Chen, M. T.; Seiferas, Joel (1985). "Efficient and Elegant Subword-Tree Construction". Combinatorial Algorithms on Words. pp. 97–107. doi:10.1007/978-3-642-82456-2_7. ISBN 978-3-642-82458-6.
* Crochemore, Maxime; Hancart, Christophe (1997). "Automata for Matching Patterns". Handbook of Formal Languages. pp. 399–462. doi:10.1007/978-3-662-07675-0_9. ISBN 978-3-642-08230-6.
* Crochemore, Maxime; Vérin, Renaud (1997). "On compact directed acyclic word graphs". Structures in Logic and Computer Science. Lecture Notes in Computer Science. 1261. pp. 192–211. doi:10.1007/3-540-63246-8_12. ISBN 978-3-540-63246-7.
* Crochemore, Maxime; Iliopoulos, Costas S.; Navarro, Gonzalo; Pinzon, Yoan J. (2003). "A Bit-Parallel Suffix Automaton Approach for (δ,γ)-Matching in Music Retrieval". String Processing and Information Retrieval. Lecture Notes in Computer Science. 2857. pp. 211–223. doi:10.1007/978-3-540-39984-1_16. ISBN 978-3-540-20177-9.
* Serebryakov, Vladimir; Galochkin, Maksim Pavlovich; Furugian, Meran Gabibullaevich; Gonchar, Dmitriy Ruslanovich (2006) (in Russian). Теория и реализация языков программирования: Учебное пособие. Moscow: MZ Press. ISBN 5-94073-094-9. http://trpl7.ru/t-books/_TRYAPBOOK_pdf.pdf.
* Faro, Simone (2016). "Evaluation and Improvement of Fast Algorithms for Exact Matching on Genome Sequences". Algorithms for Computational Biology. Lecture Notes in Computer Science. 9702. pp. 145–157. doi:10.1007/978-3-319-38827-4_12. ISBN 978-3-319-38826-7.
* Fiala, E. R.; Greene, D. H. (1989). "Data compression with finite windows". Communications of the ACM 32 (4): 490–505. doi:10.1145/63334.63341.
* Fujishige, Yuta; Tsujimaru, Yuki; Inenaga, Shunsuke; Bannai, Hideo; Takeda, Masayuki (2016). "Computing DAWGs and Minimal Absent Words in Linear Time for Integer Alphabets". 41st International Symposium on Mathematical Foundations of Computer Science (MFCS 2016). Leibniz International Proceedings in Informatics. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. pp. 38:1–38:14. doi:10.4230/LIPICS.MFCS.2016.38.
* Hopcroft, John Edward; Ullman, Jeffrey David (1979). Introduction to Automata Theory, Languages, and Computation (1st ed.). Massachusetts: Addison-Wesley. ISBN 978-81-7808-347-6.
* Inenaga, Shunsuke (2003). "Bidirectional Construction of Suffix Trees". Nordic Journal of Computing 10 (1): 52–67. https://str.i.kyushu-u.ac.jp/~inenaga/papers/NJC_bidirectional.pdf.
* Inenaga, Shunsuke; Hoshino, Hiromasa; Shinohara, Ayumi; Takeda, Masayuki; Arikawa, Setsuo; Mauri, Giancarlo; Pavesi, Giulio (2005). "On-line construction of compact directed acyclic word graphs". Discrete Applied Mathematics 146 (2): 156–179. doi:10.1016/J.DAM.2004.04.012.
* Inenaga, Shunsuke; Hoshino, Hiromasa; Shinohara, Ayumi; Takeda, Masayuki; Arikawa, Setsuo (2001). "Construction of the CDAWG for a trie". Prague Stringology Conference. Proceedings. pp. 37–48. http://www.shino.ecei.tohoku.ac.jp/~ayumi/papers/PSC2001.pdf.
* Inenaga, Shunsuke; Shinohara, Ayumi; Takeda, Masayuki; Arikawa, Setsuo (2004). "Compact directed acyclic word graphs for a sliding window". Journal of Discrete Algorithms 2: 33–51. doi:10.1016/S1570-8667(03)00064-9.
* Larsson, N.J. (1996). "Extended application of suffix trees to data compression". Proceedings of Data Compression Conference - DCC '96. pp. 190–199. doi:10.1109/DCC.1996.488324. ISBN 0-8186-7358-3.
* Mohri, Mehryar; Moreno, Pedro; Weinstein, Eugene (2009). "General suffix automaton construction algorithm and space bounds". Theoretical Computer Science 410 (37): 3553–3562. doi:10.1016/J.TCS.2009.03.034.
* Паращенко, Дмитрий А. (2007) (in Russian). Обработка строк на основе суффиксных автоматов. Saint Petersburg: ITMO University. http://is.ifmo.ru/diploma-theses/paraschenko/doc.pdf.
* Pratt, Vaughan Ronald (1973). Improvements and applications for the Weiner repetition finder. OCLC 726598262.
* Рубцов, Александр Александрович (2019) (in Russian). Заметки и задачи о регулярных языках и конечных автоматах. Moscow: Moscow Institute of Physics and Technology. ISBN 978-5-7417-0702-9. http://rubtsov.su/public/books/zz-a5-online.pdf.
* Rubinchik, Mikhail; Shur, Arseny M. (2018). "EERTREE: An efficient data structure for processing palindromes in strings". European Journal of Combinatorics 68: 249–265. doi:10.1016/J.EJC.2017.07.021.
* Senft, Martin; Dvořák, Tomáš (2008). "Sliding CDAWG Perfection". String Processing and Information Retrieval. Lecture Notes in Computer Science. 5280. pp. 109–120. doi:10.1007/978-3-540-89097-3_12. ISBN 978-3-540-89096-6.
* Slisenko, A. O. (1983). "Detection of periodicities and string-matching in real time". Journal of Soviet Mathematics 22 (3): 1316–1387. doi:10.1007/BF01084395.
* Weiner, Peter (1973). "Linear pattern matching algorithms". 14th Annual Symposium on Switching and Automata Theory (Swat 1973). pp. 1–11. doi:10.1109/SWAT.1973.13.
* Yamamoto, Jun'ichi; I, Tomohiro; Bannai, Hideo; Inenaga, Shunsuke; Takeda, Masayuki (2014). "Faster Compact On-Line Lempel-Ziv Factorization". 31st International Symposium on Theoretical Aspects of Computer Science (STACS 2014). Leibniz International Proceedings in Informatics. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. pp. 675–686. doi:10.4230/LIPICS.STACS.2014.675.

## External links

* Suffix automaton article on E-Maxx Algorithms in English

* v
* t
* e

Strings

String metric|

* Approximate string matching
* Bitap algorithm
* Damerau–Levenshtein distance
* Edit distance
* Gestalt Pattern Matching
* Hamming distance
* Jaro–Winkler distance
* Lee distance
* Levenshtein automaton
* Levenshtein distance
* Wagner–Fischer algorithm

String-searching algorithm|

* Apostolico–Giancarlo algorithm
* Boyer–Moore string-search algorithm
* Boyer–Moore–Horspool algorithm
* Knuth–Morris–Pratt algorithm
* Rabin–Karp algorithm

Multiple string searching|

* Aho–Corasick
* Commentz-Walter algorithm

Regular expression|

* Comparison of regular expression engines
* Regular tree grammar
* Thompson's construction
* Nondeterministic finite automaton

Sequence alignment|

* Hirschberg's algorithm
* Needleman–Wunsch algorithm
* Smith–Waterman algorithm

Data structures|

* DAFSA
* Suffix array
* Suffix automaton
* Suffix tree
* Generalized suffix tree
* Rope
* Ternary search tree
* Trie

Other|

* Parsing
* Pattern matching
* Compressed pattern matching
* Longest common subsequence
* Longest common substring
* Sequential pattern mining
* Sorting

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Suffix automaton. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Suffix_automaton&oldid=3979624"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template