Overview
Build a suffix automaton for the first string, then scan the second string while tracking the current automaton state, the current contiguous match length, and the best match seen so far.
Finds a longest common substring by scanning one string through the suffix automaton of another.
Compact metadata for implementation and discovery.
Build a suffix automaton for the first string, then scan the second string while tracking the current automaton state, the current contiguous match length, and the best match seen so far.
Quick facts
Runtime and memory behavior at a glance.
Best
O(n)
Average
O(n + m)
Worst
O(n + m)
Space
O(n + m)
if transition exists: length = length + 1 else follow suffix linksTracks the longest substring currently matched in the automaton.
Show walking one string through the suffix automaton of another on a small longest common substring example.
This method reports a contiguous match. It does not score edits, gaps, or noncontiguous subsequences.
What each reference supports for this entry.
String algorithms reference covering Suffix Automaton LCS recurrences, automata/indexing structures, or exact/approximate matching role.
Good next jumps from the relationship graph, ranked for useful discovery.
Data Structures · Core
A suffix array with LCP values can also find longest common substrings after combining the strings.
Compare with thisData Structures · Core
Suffix trees provide another indexed structure for longest common substring queries.
Compare with thisPattern Matching · Core
Manber-Myers Suffix Array Construction uses Suffix Automaton LCS as a subroutine, representation, or supporting idea while doubling prefix lengths and sorting suffix ranks iteratively.
Compare with thisPattern Matching · Core
Ukkonen Suffix Tree Construction uses Suffix Automaton LCS as a subroutine, representation, or supporting idea while maintaining active points and suffix links during online construction.
Compare with thisThe LCS scan relies on transitions and suffix links from a suffix automaton.
A suffix array with LCP values can also find longest common substrings after combining the strings.
Suffix trees provide another indexed structure for longest common substring queries.