Practica matemática discreta

Algorithms / Suffix Ordering

Least You Need to Know: Suffix Ordering, Lexicographic Structure, and LCP Intuition

Suffix-based reasoning sorts all suffixes of a string lexicographically. Even without implementing a full suffix array from scratch, it helps to know how lexicographic suffix order exposes repeated-substring structure and longest-common-prefix reasoning.

The least you need to know

Key notation

suffix i substring `s[i:]`
SA suffix array: starting indices in sorted suffix order
LCP longest common prefix of two suffixes

Tiny worked example

  • For string `banana`, suffixes include `banana`, `anana`, `nana`, `ana`, `na`, `a`.
  • Sorting them lexicographically places similar prefixes near each other, such as `a`, `ana`, `anana`.
  • The longest repeated substring can then be found by checking large LCP values among adjacent sorted suffixes.
  • This is the high-level reason suffix arrays are powerful.

Common mistakes

How to recognize this kind of problem

Start practice