LCP Array Primer Spec
This book is a single-page interactive lesson for the LCP array itself. It does not teach suffix-array construction in detail and does not teach the shortest unique subarray problem on the main page.
Route Contract
The default route is /books/lcp/, and it renders Chinese content by default.
The English route is /books/lcp/en.html.
The supporting specification page is available at /books/lcp/spec.html, with
the Chinese version at /books/zh/lcp/spec.html.
The page links back to /books/sa/ for suffix arrays 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, string
lengths, complexity, constraints, and formulas should use LaTeX/KaTeX whenever
possible.
Teaching Contract
The page assumes a beginner who has either read the suffix-array page or can follow the linked explanation. It explains:
- LCP as the length of the shared prefix between two strings;
lcp[p]as the shared-prefix length ofsa[p]andsa[p-1];- why sorted neighboring suffixes are enough for adjacent LCP;
rank[i]as the inverse map from original start to sorted position;- why Kasai can reuse
hand decrement it after each start.
Every micro-step must include a direct why-explanation.
Interaction Contract
The lesson must provide:
- editable string input with compact examples;
- a sorted suffix table with LCP values;
- an aligned two-suffix comparison that highlights the shared prefix;
- a Kasai trace table showing start, rank, neighbor, old
h, newh, and written LCP value; - previous and next controls plus a numbered micro-step rail;
- automatic playback with speed presets and custom millisecond interval;
- cross-links to the suffix-array book and the application problem.
Acceptance Contract
Before publishing:
npm run buildpasses.npm run check:contentpasses.npm run check:distpasses./books/lcp/opens without console errors.- Step rail, playback, speed controls, examples, stage tabs, and suffix rows all change page state.
/books/lcp/en.htmlopens correctly.