Suffix Array Primer Spec
This book is a single-page interactive lesson for suffix arrays themselves. It does not teach LCP and does not teach the shortest unique subarray problem on the main page.
Route Contract
The default route is /books/sa/, and it renders Chinese content by default.
The English route is /books/sa/en.html.
The supporting specification page is available at /books/sa/spec.html, with
the Chinese version at /books/zh/sa/spec.html.
The page links to /books/lcp/ for LCP and to
/books/sa/unique-subarray.html for the application problem.
Typography and Math Contract
This book inherits the repository-wide book style contract in
BOOK_STYLE.md: all prose, headings, controls, tables, captions, and
ordinary UI text must default to PingFang. Code blocks, inline code, terminal
snippets, and code-editor surfaces use the Cursor/LeetCode stack
Monaco, "Cascadia Code", Consolas, "Courier New", ui-monospace, SFMono-Regular, Menlo, monospace. Algorithm variables, array indices, ranks,
string lengths, complexity, constraints, and formulas should use LaTeX/KaTeX
whenever possible.
Teaching Contract
The page assumes a complete beginner and explains:
- suffix: the segment from one start to the end;
- suffix array: the sorted list of suffix starts;
- lexicographic order: compare from the first character and move right only on ties;
- rank/class: the label for prefixes that are indistinguishable at the current inspected length;
- doubling: a length
2kprefix can be compared as(rank[i], rank[i+k])once lengthkprefixes have ranks.
The page must repeatedly answer why each step is valid, not just what the next formula is.
Interaction Contract
The lesson must provide:
- editable string input with compact examples;
- a clickable character tape;
- a sorted suffix list that stores and highlights starts, not copied suffixes;
- a construction-round table showing start, suffix, comparison key, and new rank;
- a micro-step rail with previous and next controls;
- automatic playback with speed presets and custom millisecond interval;
- stage tabs that jump to the first micro-step for suffixes, order, ranks, doubling, and final result;
- links to the LCP book and application problem without explaining those topics inline.
Acceptance Contract
Before publishing:
npm run buildpasses.npm run check:contentpasses.npm run check:distpasses./books/sa/opens without console errors.- Step rail, playback, speed controls, examples, stage tabs, suffix rows, and character tape all change page state.
/books/sa/en.htmlopens correctly.