Skip to main content
Back to the DSA atlas
Strings Data structure Advanced

Suffix Automaton

Compress all substrings of a string into a linear-size automaton with suffix links.

stringautomatonrare

Interactive visualization

Use the controls to connect the idea to concrete operations before diving into the full write-up.

Active state

max length = 2

suffix link = 0

transitions: a -> 3

All states

state 0: len 0, link -, a -> 1, b -> 2
state 1: len 1, link 0, b -> 2
state 2: len 2, link 0, a -> 3
state 3: len 3, link 1, -

A compact automaton of all substrings

Each state represents an equivalence class of substring endings. Suffix links jump to the next smaller context, which is why the automaton stays linear in size.

Family

Strings

Prefix-aware structures and text-centric search strategies.

Builds on

Foundational

You can start here without another page first.

Unlocks

0 next topics

Use these follow-ups when you want to apply the current idea in a richer setting.

Learning paths

2

This topic appears in curated progressions so you can keep moving without guessing the next step.

Problem

You want a structure that captures all substrings of one string and supports rich substring analytics.

Core idea

A suffix automaton is the minimal DFA that recognizes all substrings of a string.

As you append characters one by one, you maintain states representing sets of end positions. Each state stores:

  • its longest represented substring length
  • a suffix link to the next smaller context
  • transitions by characters

Why it matters

Suffix automata are powerful because they encode a huge amount of substring information in only linear space.

They support tasks like:

  • counting distinct substrings
  • finding longest common substrings
  • tracing occurrence structure

Complexity

OperationTime
Build automatonO(n)O(n)

Many follow-up analyses remain linear or near-linear once the automaton exists.

Key takeaways

  • A suffix automaton is a compact substring machine
  • Suffix links are the main structural idea; they point to the next smaller suffix context
  • This structure is more compact and automaton-flavored than suffix arrays or tries
  • It is rare advanced string material, but it belongs in the same serious toolbox tier

Practice problems

ProblemDifficultyKey idea
Distinct Substrings references🔴 HardCount substrings via state lengths
Longest Common Substring references🔴 HardWalk another string through the automaton
String analytics references🔴 HardState transitions and suffix links

Relation to other topics

  • Suffix Array indexes suffix order; suffix automaton indexes substring state transitions
  • Aho-Corasick is another automaton, but for many patterns rather than all substrings of one text
  • Manacher focuses specifically on palindromes, not general substring structure

Related directions

These topics live nearby conceptually, even if they are not direct prerequisites.

More from Strings

Stay in the same family when you want parallel variations of the same mental model.

Paths that include this topic

Follow one of these sequences if you want a guided next step instead of open-ended browsing.

String matching

Move from prefix reuse and rolling hashes to suffix-based indexing and automata.

Substring toolkit

Compare rolling hashes, sorted suffixes, automata, and palindrome-specific structure.

From the blog

Pair the atlas with recent writing from the rest of the site when you want a broader engineering perspective alongside the topic graph.