arXiv:2610.32818cs.ITOct 2026

Manuscript Offprint

arXiv:2610.32818

Logarithmic Separation between LZ77 and LZ-End and Grammar Compression

Philip Bille, Inge Li Gørtz, Rikke Jessen, Jingxun Li, Simon Rumle Tarnow, Renfei Zhou

Introduction

The Lempel-Ziv factorization of a text [19] (LZ77) is a greedy left-to-right parse in maximal substrings such that each substring is either a single (new) character or already occurred to the left. Despite its simplicity, LZ77 can be easily shown to be optimal among all unidirectional parses (i.e. that copy phrases from left-to-right), and dominates other popular compression schemes such as Straight Line Programs (SLPs), i.e., context-free grammars that generate only the text as output.

LZ-End [14, 15] is a variant of LZ77 parsing with the added constraint that the source of the phrase must end at a phrase boundary of a previous phrase. Let z(S)z(S) be the number of phrases in the LZ77 parsing of a string SS, and let zno(S)z_{\text{no}}(S) be the number of phrases when overlaps are not allowed between phrases and their sources. Lastly, let zend(S)z_{\text{end}}(S) be the minimum number of phrases in any legal LZ-End parsing of SS. While there is no known data structure of O(z(S))O(z(S)) size that provides efficient random access to arbitrary positions in the string, it was recently shown that O~(1)\tilde{O}(1) time access could be achieved with O(zend(S))O(z_{\text{end}}(S)) space [4]. Note that, every LZ-End parsing is also a legal unidirectional parse, so zno(S)≤zend(S)z_{\text{no}}(S) \leq z_{\text{end}}(S).

In this paper we answer the following question: How much can the source-boundary restriction increase the number of phrases?

Our results. We give an explicit, deterministic family of binary strings TkT_{k}, indexed by k, where k is a power of two, such that

∣Tk∣=Θ(k2log⁡k),zno(Tk)=O(k),zend(Tk)=Ω(klog⁡k).|T_{k}|=\Theta(k^{2}\log k),\qquad z_{\mathrm{n o}}(T_{k})=O(k),\qquad z_{\mathrm{e n d}}(T_{k})=\Omega(k\log k).

Writing n=∣Tk∣n = |T_k|, we obtain

zend(Tk)zno(Tk)=Ω(log⁡n).\frac{z_{\mathrm{e n d}}(T_{k})}{z_{\mathrm{n o}}(T_{k})}=\Omega(\log n).

The lower bound holds for every legal LZ-End parsing, with unrestricted choices of source occurrences and phrase boundaries.

The result has a consequence for grammar compression. Let g(S)g(S) denote the minimum total length of the right-hand sides of an acyclic grammar generating only SS. The grammar-to-LZ77 conversion of Charikar et al. [5] also produces a legal LZ-End parsing: expand a variable at its first occurrence and copy each subsequent occurrence from that first expansion, which ends at a phrase boundary. Thus zend(S)≤g(S)z_{\text{end}}(S) \leq g(S), and our strings also satisfy

g(Tk)zno(Tk)=Ω(log⁡n).\frac{g(T_{k})}{z_{\mathrm{n o}}(T_{k})}=\Omega(\log n).

The same asymptotic separation holds when grammar size is measured by the number of variables in a binary straight-line program (SLP). We give the conversion argument explicitly in

Section 2.1. Together with the standard LZ77-to-grammar upper bound g(S)=O(zno(S)log⁡n)g(S) = O(z_{\text{no}}(S) \log n), these inequalities show that the worst-case ratios to non-overlapping LZ77 are Θ(log⁡n)\Theta(\log n) for both optimal LZ-End and smallest grammars.

The snapshot construction. We first work over a growing alphabet. Start with a string A0A_0 of kk distinct symbols. Change one position at a time to a fresh symbol to get A1A_1, choosing the changing positions in bit reversal order [16, 18, 8], and concatenate A0…AkA_0 \ldots A_k with fresh separators between them. Each version differs from its predecessor at exactly one position. LZ77 can therefore represent the string by a prefix copy, the new symbol, and a suffix copy, giving O(k)O(k) phrases in total.

For the LZ-End lower bound, place a complete balanced binary tree over the string positions in A0A_0. At each node, consider consecutive updates within its interval where the first update is in the left child and the next is in the right child. Bit reversal produces k/2k/2 such events per tree level, for a total of (klog⁡2k)/2(k \log_2 k)/2. We show that each event requires a distinct phrase in every LZ-End parsing.

The charging argument finds a phrase between the two updates of each event. Between two such updates of symbols in the interval of a node v, choose the smallest position j in the right child of v that is a phrase boundary in some AiA_i between the two updates, and then the smallest i such that AiA_i contains that boundary. The preceding boundary lies in the left child. If its phrase started before the position changed by the left update, the phrase would contain that update's fresh symbol. A source for the phrase would then have to occur after that update and end at j. This contradicts the choice of the smallest i such that AiA_i contains that boundary. Hence the two phrase boundaries lie in opposite children of the node, and between the two update times. The lowest common ancestor of the two boundary coordinates identifies the node uniquely, and since the row intervals of events at the same node are disjoint, no phrase can receive two charges.

To obtain the result for binary strings, we encode the symbols with fixed-length codewords whose headers identify codeword starts. A fresh codeword forces a phrase boundary strictly inside it. The charging argument can therefore be repeated in bit coordinates, without assuming that parsing boundaries align with codewords. Any copied phrase containing a complete codeword for an updated symbol identifies both its array position and the alignment of its source. Finally, numbering fresh symbols in order of appearance allows each new codeword to be represented by a constant number of non-overlapping LZ77 copies. The encoding preserves the O(k)O(k) LZ77 bound and the Ω(klog⁡k)\Omega(k \log k) LZ-End lower bound.

Finally, we show that the result also holds for the version of LZ-End and LZ77 where a phrase consists of a copy and an extra character. This follows immediately from the fact that the two versions of the parsing only differ by a factor of 2 (for completeness, we prove this in Section 5.