Papers
Topics
Authors
Recent
Search
2000 character limit reached

Lyndon Grammar: Efficient Compression & Indexing

Updated 22 January 2026
  • The Lyndon Grammar Approach is defined by the unique factorization of strings into Lyndon words, enabling concise grammar-based compression.
  • It leverages combinatorial structures like Lyndon trees and straight-line programs to facilitate efficient Burrows-Wheeler Transform construction and self-indexing.
  • By exploiting repetitive patterns in massive datasets, the method achieves significant compression and enhanced performance in text indexing and pattern matching.

The Lyndon grammar approach applies the combinatorial theory of Lyndon words to grammar-based text compression and efficient sequence indexing. By leveraging the unique factorization of strings into Lyndon factors and exploiting repetitiveness, Lyndon grammars enable compact grammar representations, facilitate efficient Burrows-Wheeler Transform (BWT) construction, and support self-indexing on massive datasets with potentially exponential input size. This method provides both theoretical and practical advances in grammar compression, compressed computation, and succinct data structure design.

1. Definitions: Lyndon Words, Factorization, and the Lyndon Tree

Let Σ\Sigma be a totally ordered alphabet. A non-empty word w∈Σ+w \in \Sigma^+ is a Lyndon word if, for every nontrivial rotation vv of ww, one has w<vw < v in the lexicographic order. Equivalently, ww is strictly lexicographically smaller than any of its proper non-empty suffixes. The foundation for the Lyndon grammar approach is the Chen–Fox–Lyndon theorem: every string S∈Σ+S \in \Sigma^+ can be factorized uniquely as

S=L1L2⋯Lk,S = L_1 L_2 \cdots L_k,

where each LiL_i is a Lyndon word and L1≥L2≥⋯≥LkL_1 \geq L_2 \geq \dots \geq L_k lexicographically. This is known as the Lyndon factorization of w∈Σ+w \in \Sigma^+0, and can be computed in linear time for explicit inputs via Duval's algorithm (Olbrich, 27 Apr 2025, Tsuruta et al., 2020, Badkobeh et al., 2020).

A pivotal recursive structure induced by the standard factorization (for a Lyndon word w∈Σ+w \in \Sigma^+1 of length at least w∈Σ+w \in \Sigma^+2, there is a unique decomposition w∈Σ+w \in \Sigma^+3 such that w∈Σ+w \in \Sigma^+4 is the longest proper suffix of w∈Σ+w \in \Sigma^+5 which itself is Lyndon) is the Lyndon tree, a full binary tree where each inner node corresponds to a standard factorization of a Lyndon substring. This tree structure directly corresponds to a context-free grammar (straight-line program, SLP) whose nonterminals expand according to these Lyndon splits (Tsuruta et al., 2020, Badkobeh et al., 2020).

2. Grammar Construction: The Lyndon SLP and Algorithmic Variants

A straight-line program (SLP) is a context-free grammar in Chomsky normal form that derives exactly one string. In the Lyndon grammar approach, a Lyndon SLP w∈Σ+w \in \Sigma^+6 is constructed so that:

  • Each nonterminal w∈Σ+w \in \Sigma^+7 expands according to the standard factorization of the Lyndon word it generates, i.e., w∈Σ+w \in \Sigma^+8 if w∈Σ+w \in \Sigma^+9 and this matches the standard factorization.
  • Terminals are rules of the form vv0 for vv1.
  • For multiple input sequences (e.g., in multiset or collection settings), several start symbols vv2 can be used, whose derived words are Lyndon and ordered vv3 lexicographically (Olbrich, 27 Apr 2025).

The construction can be performed via several algorithmic variants:

Algorithm Time Complexity Working Memory Notes
Naïve stack + suffix compare vv4 vv5 Simple; uses explicit comparisons for merging
Sorted B-tree variant vv6 vv7 Lex order comparison via balanced trees
Randomized hash variant vv8 expected vv9 Fastest; merges via hashing of subtree pairs

Here, ww0 is the input text length, ww1 is the number of distinct Lyndon subtrees (grammar size), and the working memory always depends on ww2. On highly repetitive inputs, typically ww3 (Olbrich, 27 Apr 2025, Tsuruta et al., 2020).

An alternative, left-to-right construction based on the left Lyndon suffix table and tree achieves ww4 letter-comparison cost for explicit input and produces a Lyndon-tree grammar with at most ww5 symbols for input of length ww6 (Badkobeh et al., 2020).

3. Properties of the Lyndon Grammar: Rules, Size, and Structure

Lyndon grammars are uniquely determined by their standard factorizations, with the following properties:

  • Nonterminals are introduced via the standard factorization test: whenever two consecutive Lyndon factors can be merged (by checking if their concatenation remains Lyndon), a rule ww7 is created.
  • The grammar grows only when such merges succeed; this is highly beneficial on repetitive data where identical Lyndon subtrees recur, leading to significant reduction ww8 (Olbrich, 27 Apr 2025).
  • For a grammar ww9 with w<vw < v0 non-terminal rules and w<vw < v1 start symbols: w<vw < v2.
  • Depth and structure: The depth of the grammar, w<vw < v3, is determined by the height of the underlying Lyndon forest. For random strings, w<vw < v4; for the worst case, w<vw < v5 but is much smaller in practical, repetitive sequences (Olbrich, 27 Apr 2025, Badkobeh et al., 2020).
  • For collection input, each sequence is reduced to its unique Lyndon root (lexicographically minimal rotation), and concatenation proceeds in decreasing order (Olbrich, 27 Apr 2025).

A crucial distinction is that all identical Lyndon subtrees (i.e., repeated Lyndon factors) are merged into a single nonterminal, enabling compactness analogous to RePair and other grammar-based compressors, yet tailored to the combinatorics of repetitions and periodicities within the Lyndon factor lattice (Tsuruta et al., 2020).

4. Applications: BWT Construction, Self-Indexing, and Pattern Matching

Efficient BWT and eBWT Construction

A primary application of the Lyndon grammar approach is the construction of the Burrows-Wheeler Transform (BWT) and extended-BWT (eBWT) directly from the grammar without full decompression:

  • After sorting the nonterminals lexicographically, the BWT can be induced in a single left-to-right pass over the grammar, emitting run-length encoded (RLE) BWT representations.
  • For each grammar rule w<vw < v6, positions in the text corresponding to w<vw < v7's infinite-periodic order yield adjacent BWT runs.
  • The procedure maintains a list w<vw < v8 of runs and streams them in grammar order to output the RLE-BWT in w<vw < v9 time and ww0 space (plus ww1 for RLE output, where ww2 is number of runs) (Olbrich, 27 Apr 2025).

For the eBWT over a collection ww3, each ww4 is first canonicalized to its Lyndon root, then the same procedure applies to the ordered concatenation (Olbrich, 27 Apr 2025).

Self-Indexing

Lyndon SLPs support compressed self-indexing with ww5 space:

  • Pattern matching for a pattern ww6 of length ww7 over a text compressed by its Lyndon SLP (size ww8) can be performed in ww9 time, where S∈Σ+S \in \Sigma^+0 is the original text length and S∈Σ+S \in \Sigma^+1 is number of pattern occurrences.
  • The approach identifies "partition pairs," i.e., possible divisions of S∈Σ+S \in \Sigma^+2 induced by grammar productions into suffix/prefix alignments with Lyndon factors. The number of significant suffixes (candidates) for such divisions is S∈Σ+S \in \Sigma^+3 (Tsuruta et al., 2020).
  • All structures (SLP, finger-printing, random-access, z-fast tries) can be built in S∈Σ+S \in \Sigma^+4 expected time using appropriate data structures (Tsuruta et al., 2020).

Compressed Lyndon Factorization

Given a string S∈Σ+S \in \Sigma^+5 in grammar-compressed form (SLP of size S∈Σ+S \in \Sigma^+6, height S∈Σ+S \in \Sigma^+7), its Lyndon factorization can be computed in S∈Σ+S \in \Sigma^+8 time and S∈Σ+S \in \Sigma^+9 space, with S=L1L2⋯Lk,S = L_1 L_2 \cdots L_k,0 the factorization size. This is the first such polynomial time result when S=L1L2⋯Lk,S = L_1 L_2 \cdots L_k,1 may be exponentially large in S=L1L2⋯Lk,S = L_1 L_2 \cdots L_k,2 (I et al., 2013).

5. Empirical and Theoretical Performance

Experimental results confirm that Lyndon grammar-based algorithms are efficient on large, highly repetitive datasets:

  • Datasets comprising gigabase-scale genomic collections (human haplotypes, SARS-CoV-2 genomes), with up to S=L1L2⋯Lk,S = L_1 L_2 \cdots L_k,3 symbols, are processed.
  • Compared with SA-IS, Big-BWT, recursive PFP, and other advanced BWT tools, the Lyndon grammar approach yields BWT/eBWT up to S=L1L2⋯Lk,S = L_1 L_2 \cdots L_k,4–S=L1L2⋯Lk,S = L_1 L_2 \cdots L_k,5 faster or using S=L1L2⋯Lk,S = L_1 L_2 \cdots L_k,6–S=L1L2⋯Lk,S = L_1 L_2 \cdots L_k,7 less RAM, especially under multithreading.
  • Grammar construction is the bottleneck (~98% of total runtime in fastest variants), yet even naïve implementations outperform many specialized parsers for real data.
  • Parallel scaling is favorable: up to 32 threads, wall time reduces to approx S=L1L2⋯Lk,S = L_1 L_2 \cdots L_k,8th baseline; memory increases moderately to accommodate thread-safe data structures (Olbrich, 27 Apr 2025).

Theoretical guarantees ensure that grammar size is minimized by merging identical subtrees, with worst-case size linear in input but much smaller on repetitive texts. Deep grammars arise only in contrived worst-case patterns (e.g., S=L1L2⋯Lk,S = L_1 L_2 \cdots L_k,9) (Olbrich, 27 Apr 2025, Badkobeh et al., 2020).

6. Limitations and Open Directions

Key limitations include:

  • Lyndon grammar construction requires LiL_i0 working memory and may be LiL_i1 in the worst case, although practical performance is superior on repetitive inputs.
  • Suffix-comparison variants trade off simplicity and speed; efficient hashing or balanced tree variants mitigate worst-case behavior at the cost of algorithmic complexity (Olbrich, 27 Apr 2025).
  • The minimal grammar problem remains NP-hard; Lyndon-based SLPs are not always size-optimal compared to Sequitur, RePair, or other compressors, though they are more canonical and better-suited for certain combinatorial properties (Badkobeh et al., 2020).
  • Future work directions include improved parallelization, support for very large diverse collections with 64-bit symbol tables, and seeking faster algorithms for Lyndon factorization when input is in LZ78 or other compressed forms (Olbrich, 27 Apr 2025, I et al., 2013).

7. Connections to Other Compressed Computation and Stringology

The Lyndon grammar approach unifies combinatorics on words, compressed data structures, and efficient algorithm design. It provides a means to:

  • Relate grammar-based compression to lex order and repetitive structure via the unique properties of Lyndon words;
  • Extend SLP techniques with canonical binary trees reflecting periodicities in input, benefiting pattern matching and suffix sorting tasks;
  • Suggest new optima in run-length encoding for BWT, self-indexing, and compressed computation in massive genomics or text repositories (Olbrich, 27 Apr 2025, Tsuruta et al., 2020, Badkobeh et al., 2020).

A plausible implication is that the Lyndon grammar approach, by canonically capturing repetitive structure, can serve as a foundation for advanced compressed computation (indexing, matching, transform computation) where both theory and practice require handling extremely large, repetitive datasets efficiently.

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Lyndon Grammar Approach.