ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
SuffixAutomaton.h File Reference

The suffix automaton (the directed acyclic word graph, DAWG) of a string \( S \) of \( n \) bytes, beyond the book: the smallest deterministic automaton that accepts the suffixes of \( S \), whose paths from the start spell exactly the substrings of \( S \). More...

#include "ADS/Contract.h"
#include <cstddef>
#include <cstdint>
#include <string_view>
#include <utility>
#include <vector>
#include "ADS/string/impl/SuffixAutomaton.tpp"

Go to the source code of this file.

Classes

class  ADS::SuffixAutomaton
 the suffix automaton of a string, built a byte at a time More...

Namespaces

namespace  ADS

Detailed description

The suffix automaton (the directed acyclic word graph, DAWG) of a string \( S \) of \( n \) bytes, beyond the book: the smallest deterministic automaton that accepts the suffixes of \( S \), whose paths from the start spell exactly the substrings of \( S \).

Its states are the classes of the substrings by their sets of end places,

\[ \mathrm{endpos}( u ) = \{ j : S[ j - |u| + 1 .. j ] = u \} , \]

a class holding the suffixes of its longest member of lengths in \( ( \mathit{len}( \mathit{link}( v ) ) , \mathit{len}( v ) ] \), where the suffix link of \( v \) is the class of the longest suffix in another class. It has at most \( 2 n - 1 \) states (\( n \ge 2 \)) and \( 3 n - 4 \) transitions (\( n \ge 3 \)), and the construction of Blumer et al. adds the bytes one at a time: the new state of \( S c \) gets the transitions on \( c \) from the suffix path of the last state, which stops at the first state \( p \) that has one; if it leads to \( q \) with \( \mathit{len}( q ) = \mathit{len}( p ) + 1 \), then \( q \) is the new link, otherwise \( q \) is cloned with that length, in \( O( n ) \) amortized time for a constant alphabet. Here the transitions of a state are a short vector of pairs (byte, state), searched linearly, so that the time is \( O( n \sigma ) \) for \( \sigma \) distinct bytes.

  • contains( P ) follows \( P \) from the start, \( O( |P| \sigma ) \);
  • occurrences( P ) is the size of the end set of the state of \( P \), counted once for all by adding the count of each state (1 if it ends a prefix of \( S \), 0 for a clone) to its link, in decreasing order of the lengths;
  • distinctSubstrings() is \( \sum_{v \ne \mathit{start}} ( \mathit{len}( v ) - \mathit{len}( \mathit{link}( v ) ) ) \), the number of nonempty distinct substrings of \( S \);
  • longestCommonSubstring( T ) scans \( T \) keeping the longest suffix of \( T[ 0 .. j ] \) that is a substring of \( S \), following the links on a mismatch, \( O( |T| \sigma ) \).

The contracts [see Contract.h]: at most \( 2 n \) states (an invariant), and the results equal those of the definitions on the substrings (the audits of the tests). The functions are defined in SuffixAutomaton.tpp.

See also
A. Blumer, J. Blumer, D. Haussler, A. Ehrenfeucht, M. T. Chen, J. Seiferas, The smallest automaton recognizing the subwords of a text, Theoretical Computer Science 40, 31-55, 1985, doi:10.1016/0304-3975(85)90157-4
M. Crochemore, Transducers and repetitions, Theoretical Computer Science 45, 63-86, 1986, doi:10.1016/0304-3975(86)90041-1
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa