Abstract 1 Introduction 2 Preliminaries 3 LZBE Factorization 4 Data Structure for Efficient Random Access 5 Linear-time Computation of the Greedy LZBE Factorization 6 Conclusion References Appendix A A Lower Bound on the Approximation Ratio of Greedy to Optimal LZBE Factorization

LZBE: An LZ-Style Compressor Supporting O(logn)-Time Random Access

Hiroki Shibata ORCID Joint Graduate School of Mathematics for Innovation, Kyushu University, Fukuoka, Japan    Yuto Nakashima ORCID Department of Informatics, Kyushu University, Fukuoka, Japan    Yutaro Yamaguchi ORCID Department of Information and Physical Sciences, Osaka University, Japan    Shunsuke Inenaga ORCID Department of Informatics, Kyushu University, Fukuoka, Japan
Abstract

An LZ-like factorization of a string divides it into factors, each being either a single character or a copy of a preceding substring. While grammar-based compression schemes support efficient random access with space linear in the compressed size, no comparable guarantees are known for general LZ-like factorizations. This limitation motivated restricted variants such as LZ-End [Kreft and Navarro, 2013] and height-bounded LZ (LZHB) [Bannai et al., 2024], which trade off some compression efficiency for faster access. In this paper, we introduce LZ-Begin-End (LZBE), a new LZ-like variant in which every copy factor must refer to a contiguous sequence of preceding factors. This structural restriction ensures that any context-free grammar can be transformed into an LZBE factorization of the same size. We further study the greedy LZBE factorization, which selects each copy factor to be as long as possible while processing the input from left to right, and show that it can be computed in linear time. Moreover, we exhibit a family of strings for which the greedy LZBE factorization is asymptotically smaller than the smallest grammar. These results demonstrate that the LZBE scheme is strictly more expressive than grammar-based compression in the worst case. To support fast queries, we propose a data structure for LZBE-compressed strings that permits O(logn)-time random access within space linear in the compressed size, where n is the length of the input string.

Keywords and phrases:
data compression, Lempel–Ziv parsing, string algorithms, random access
Funding:
Yuto Nakashima: JSPS KAKENHI Grant Number JP25K00136
Yutaro Yamaguchi: JSPS KAKENHI Grant Numbers JP20K19743, JP20H00605, and JP25H01114, and JST CRONOS Japan Grant Number JPMJCS24K2
Shunsuke Inenaga: JSPS KAKENHI Grant Numbers JP23K18466 and JP23K24808
Copyright and License:
[Uncaptioned image] © Hiroki Shibata, Yuto Nakashima, Yutaro Yamaguchi, and Shunsuke Inenaga; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Data compression
Editors:
Philip Bille and Nicola Prezza

1 Introduction

Data compression is a fundamental technique for reducing storage and transmission costs in large-scale data processing. Its importance is particularly evident for highly repetitive string collections, which share many long repeated patterns. Such data naturally arise in various domains, including version-controlled data and genomic databases, and exhibit substantial redundancy that can be effectively exploited by modern compression algorithms [20].

Computing directly on compressed data without decompressing it into its original form is a fundamental task in data compression and compressed data structures. Among those studied in this context, random access to retrieve any character of the original text on its compressed representation is one of the most fundamental and widely studied problems [8, 15]. Efficient random access is a core primitive for various higher-level operations in compressed space and thus plays a central role in the design of compressed data structures.

A Lempel-Ziv (LZ)-like factorization is a factorization of a string in which each factor is either a single character or a copy of an earlier substring of the same text. First introduced nearly fifty years ago [17], LZ-like factorization has remained a central framework of both theory and practice, powering classic tools such as gzip and still forming a core component of modern compressors like zstd and brotli [1, 11, 12].

In general, stronger compression tends to introduce more complex dependency structures, making efficient queries on compressed data more difficult. This trade-off is well illustrated by the contrast between grammar-based and LZ-like compression schemes. A grammar-based compression is known to be asymptotically at least as large as the corresponding LZ factorization for every string [22], but it allows for random access in O(logn) time using linear space in the size of the compressed representation [8], where n denotes the length of the input text. In contrast, despite achieving stronger compression, no known data structure supports polylogarithmic time random access for general LZ-like factorizations.

These observations naturally lead to a fundamental theoretical question: what is the smallest class of compression schemes that supports efficient random access, ideally in O(logn) time? To address this question, recent studies have explored restricted variants of LZ-like factorizations that impose structural constraints on copy relationships, aiming to retain much of the compression efficiency of LZ while allowing efficient random access [4, 16, 18].

Contributions.

This paper proposes the LZ-Begin-End (LZBE) factorizations, a new class of LZ-like factorizations in which each copy factor refers to a contiguous sequence of preceding factors, i.e., both the begin and end positions of the reference must align with factor boundaries. LZBE lies between grammar-based compression and LZ-Begin/LZ-End in terms of structure and compression performance. Our contributions are summarized as follows:

  1. 1.

    We clarify the theoretical relationship between LZBE factorizations and grammar-based compression. First, we show that any context-free grammar can be converted into an LZBE factorization without increasing its size. We then prove that the greedy LZBE factorization can be asymptotically smaller than the smallest grammar, and establish a matching upper bound on the grammar–LZBE size ratio. Together, these results establish the relationship between the two representations with matching upper and lower bounds.

  2. 2.

    We propose a linear-space compressed data structure that supports random access in O(logn) time. This establishes LZBE as one of the smallest known compression schemes that support O(logn)-time random access using space linear in the compressed size.

  3. 3.

    We present a linear-time algorithm for computing the greedy LZBE factorization.

Related Works.

To address the limitations of traditional LZ-like factorizations, several restricted variants have been proposed, including LZ-Begin/LZ-End [16] and Height-Bounded LZ (LZHB, also known as BAT-LZ) [4, 18]. These variants aim to support efficient random access while keeping space usage linear in their compressed size. LZ-Begin/LZ-End restricts each copy factor to reference a previous substring that begins/ends at a factor boundary, whereas LZHB constrains the height of the dependency graph formed by copy relationships.

The LZ-End index [15] allows for random access in O(log4nloglogn) time on LZ-End compressed strings. However, that work establishes only the “existence” of such a data structure and does not provide an efficient construction algorithm. The authors note that the construction achieving the worst-case polylogarithmic query time is only known to run in expected polynomial time and no deterministic variant is known. Improving either the construction time or derandomization remains an open problem.

In contrast, LZHB with a maximum height of O(polylogn) naturally supports O(polylogn)-time random access. Nevertheless, the theoretical understanding of LZHB remains limited. Given an arbitrary LZ-like factorization (even when restricted to LZ-Begin/LZ-End), how to “balance” the factorization without increasing its size is still an open problem. Moreover, it is known that finding the smallest parsing under a given height bound is NP- and APX-hard [10]. Therefore, it remains unclear whether LZHB can outperform other LZ-like factorization methods.

2 Preliminaries

Let Σ be a set of symbols called the alphabet, and Σ the set of strings. An element of Σ is called a character. We denote a string T of length n as T=T[1]T[n], where T[i] is the i-th character of T. We denote the substring from position i to position j in T by T[i,j], for 1ijn. A sequence =(F1,,Ff) of non-empty strings such that T=F1Ff is called a factorization of T. Each element Fi is called a factor. Throughout this paper, we use n to denote the length of T.

A context-free grammar (CFG) generating a single string consists of the set Σ of terminals, the set 𝒳 of nonterminals, the set of production rules where each X𝒳 has exactly one rule, and the start symbol S𝒳. We assume the derivation relation is acyclic, so that each nonterminal X expands to a unique string exp(X). The size of the grammar is the total number of symbols on the right-hand sides of all production rules. Let gOPT denote the size of the smallest CFG generating a given string T. A straight-line program (SLP) is a CFG in Chomsky normal form, where each rule is either Xc for cΣ, or XYZ for Y,Z𝒳. Any CFG of size g can be converted into an equivalent SLP of size O(g).

A Lempel–Ziv (LZ)-like factorization [26] is a factorization in which each factor is either a single character or a substring that occurs earlier in the string. It is known that the LZ-like factorization obtained by scanning the string left to right and greedily selecting the longest valid factor at each step minimizes the number of factors. For an LZ-like factorization , we refer to factors that are the single character of the first occurrence as char factors, and those that copy a previous occurrence as copy factors. Let copy denote the set of all copy factors. For any factor Fi, define posL(Fi)=j=1i1|Fj|+1 and posR(Fi)=j=1i|Fj|. For each copy factor Ficopy, we fix one of its earlier occurrences in F1Fi and define srcL(Fi) and srcR(Fi) as its beginning and ending positions in T. Given a position 1pn, we define rel(p) as the pair (F,r) where F is the factor containing the position p and r=pposL(F)+1 is the relative position of p within F. Conversely, given a factor F and a relative position 1r|F|, the absolute position in T is given by abs(F,r)=posL(F)+r1.

Since every copy factor refers to an earlier occurrence, the original string can be restored using only an LZ-like factorization. We define the jump function jump(F,r) for a copy factor Fcopy and position 1r|F| as jump(F,r)=rel(q), where q=srcL(F)+r1 is the position in T that F[r] refers to. Given a pair (F,r), the jump sequence is defined as the sequence (Fi0,r0),(Fi1,r1),,(Fik,rk) such that (Fi0,r0)=(F,r) and (Fit+1,rt+1)=jump(Fit,rt) for all t<k, where Fik is a char factor representing T[abs(F,r)]. This sequence traces the chain of references back to the character’s first occurrence. To restore a character T[p], we follow the jump sequence from rel(p) and return the character in the final pair.

A dependency DAG 𝒟=,E for an LZ-like factorization is a directed acyclic graph where E={(Fi,Fj)×[posL(Fj),posR(Fj)][srcL(Fi),srcR(Fi)]}. The outgoing edges from each node Fi are ordered to follow the left-to-right order of the factors. In this DAG, a jump to a source factor corresponds to traversing an edge, and a jump sequence corresponds to a path to a vertex representing a char factor.

3 LZBE Factorization

In this section, we introduce a new factorization scheme called LZ-Begin-End (LZBE) and explore its relationships with other compression schemes.

An LZ-Begin-End (LZBE) factorization of a string T is an LZ-like factorization =(F1,,Fzbe) in which every copy factor must have a previous occurrence that begins and ends at factor boundaries. Hence, each copy factor corresponds to a concatenation of a contiguous sequence of preceding factors. Formally, for every copy factor Fi, there exist integers 1jk<i such that Fi=FjFj+1Fk. The greedy LZBE factorization of a string T is defined as the LZBE factorization obtained by scanning T from left to right and, at each step, selecting the longest valid factor that satisfies the LZBE condition. We note that the greedy LZBE factorization is not necessarily the smallest LZBE factorization (see Appendix A). Let zbeg and zbeOPT denote the number of factors in the greedy and the smallest LZBE factorizations of T, respectively.

Since each copy factor refers to a contiguous sequence of preceding factors, an LZBE factorization naturally defines a context-free grammar. Specifically, for each copy factor Ficopy of the form Fi=FjFk, we define the rule FiFjFk, and for each char factor Fi representing c, we define the rule Fic. The start symbol S is defined by the rule SF1Fzbe. This grammar generates T, and its size is O(zbe2), since each copy factor may refer to up to O(zbe) factors. In this sense, the LZBE factorization can be seen as a compact representation of a CFG with a specific form, where each rule produces either a single character or a contiguous sequence of existing nonterminals. Figure 1 shows an LZBE factorization and its corresponding grammar.

Figure 1: The greedy LZBE factorization of ababbababab and the pruned derivation tree of the corresponding CFG. Dotted lines and arrows indicate the sources of copy factors.

As is shown above, an LZBE factorization can be viewed as a compact representation of a CFG with a specific structure. Despite this restricted form, any CFG can be represented as an LZBE factorization without increasing its size.

Theorem 1.

Given a CFG of size g representing string T, we can construct an LZBE factorization with at most g factors.

Proof.

We apply the grammar decomposition [22] to T, which prunes all subtrees rooted at non-leftmost occurrences of nonterminals in the derivation tree. Each leaf in the pruned tree becomes a factor: terminals form char factors, and pruned nonterminals form copy factors referring to their leftmost occurrence. Since each nonterminal appears at most once as an internal node, the number of factors is bounded by g. As each copy factor refers to the concatenation of leaves (i.e., factors) in a subtree, it refers to a consecutive preceding factors. Hence, the resulting factorization is an LZBE factorization. This theorem immediately implies that zbeOPTgOPT. Figure 2 shows an example of a grammar and its corresponding LZBE factorization.

Figure 2: The derivation tree of a grammar generating abaabaabaab (left) and its pruned derivation tree (right). The LZBE factorization corresponding to the grammar is shown below the pruned tree.

The above discussion shows that the LZBE scheme is at least as powerful as grammar compression. A natural question is whether they are asymptotically equivalent or strictly stronger. To address this, we present the following theorem.

Theorem 2.

For an arbitrarily large m, there is a string T with |T|Θ(m) such that gOPTΩ(zbegα(zbeg)), where α(x) denotes the functional inverse of Ackermann’s function.

To prove this, we consider the off-line range-product problem (ORPP).

Definition 3 ([9]).

The off-line range-product problem (ORPP) is defined as follows:

Input:

a sequence (a1,,am)𝒳m, and a sequence of pairs of integers (l1,r1),,(lm,rm) such that 1lirim for all i.

Output:

a sequence (q1,,qm)𝒳m such that qi=j=liriaj for each i.

Here, 𝒳 is a set and is a binary operation such that (𝒳,) forms a semigroup.

The following lower bound is known for this problem:

Theorem 4 ([9]).

For an arbitrarily large m, there exists an input to ORPP that requires Ω(mα(m)) semigroup operations, where mO(m).

We construct an input string T for ORPP over the alphabet Σ={x1,,xm,$1,,$m+1} as follows:

T=x1xm$1Q1$2Q2$3$mQm$m+1, where Qi=xlixri.

We refer to each character $i as a delimiter character, and let Σx={x1,,xm} be the set of non-delimiter characters. The greedy LZBE factorization of T consists of the first m characters and each delimiter as a char factor, and each substring xlixri as a copy factor referring to [li,ri]. Thus, zbegΘ(m) holds. We now show the following lemma.

Lemma 5.

If there exists a CFG 𝒢 of size g producing T, the answer of ORPP can be computed by O(g) semigroup operations.

Proof.

We first convert the input CFG 𝒢 into an equivalent SLP 𝒢 of size O(g). Since T contains 2m+1 distinct characters, we have gΩ(m). For any nonterminal X, let head(X) and tail(X) denote the longest prefix and suffix of exp(X) consisting of non-delimiter characters, respectively. For any string C=xt1xt|C| over Σx, we define val(C)=j=1|C|xtj. We compute val(head(X)) and val(tail(X)) for each nonterminal X in a bottom-up fashion. For rules Xxi, the values are trivially xi. For a nonterminal X with a rule XYZ, the values are computed as follows:

val(head(X)) ={val(head(Y))if exp(Y) contains a delimiter,val(head(Y))val(head(Z))otherwise,
val(tail(X)) ={val(tail(Z))if exp(Z) contains a delimiter,val(tail(Y))val(tail(Z))otherwise.

An example of computing val(head(X)) and val(tail(X)) using the rules above is shown in Figure 3. Since the total number of nonterminals is O(g), we can compute val(head(X)) and val(tail(X)) for all nonterminals using O(g) semigroup operations.

Since T contains delimiters $1,,$m+1 in order, for each 1im, there exists a unique rule XYZ such that Y contains $i and Z contains $i+1. For such a rule, the string Qi corresponding to the i-th query range can be represented as Qi=tail(Y)head(Z). Thus, the value qi of the i-th range-product query can be computed by

qi=val(Qi)=val(tail(Y)head(Z))=val(tail(Y))val(head(Z)).

After computing val(head(X)) and val(tail(X)) for all X, we can compute all qi in O(m) time. Thus, the total number of operations required is O(g+m)=O(g). We are now ready to prove Theorem 2.

Proof of Theorem 2.

Let m be an arbitrarily large integer, and consider an ORPP instance requiring Ω(mα(m)) semigroup operations by Lemma 4. Construct the string T from this instance as described earlier. The greedy LZBE factorization of T has size zbegΘ(m). Assume, for contradiction, that gOPTo(zbegα(zbeg)) for such a string T. Then, by Lemma 3, the ORPP instance could be solved in O(g) operations, contradicting the lower bound Ω(mα(m))=Ω(zbegα(zbeg)). Therefore, the theorem holds.

Conversely, we can also prove that the above lower bound is tight even when considering the ratio between the smallest grammar size and the smallest LZBE factorization size. This is shown by a reduction to the same problem together with an existing upper bound of ORPP.

Theorem 6 ([2]).

ORPP can be solved using O(mα(m)) semigroup operations. More precisely, for any input instance of ORPP, there exists a sequence (b1,,bt)𝒳t of length tO(mα(m)) such that

  1. 1.

    For each 1im, bi=ai,

  2. 2.

    For each m+1it, there exist integers 1cidi<i such that bi=bcibdi, and

  3. 3.

    For each 1im, there exists an integer ei with bei=qi.

The construction given in the theorem directly yields an SLP of size O(mα(m)), because the sequences (b1,,bt), (cm+1,,ct), and (dm+1,,dt) can be interpreted as a derivation sequence of nonterminals.

Corollary 7.

For any input instance of ORPP, there exists an SLP of size O(mα(m)) over the terminal alphabet Σa={a1,,am} such that, for each 1im, there exists a nonterminal Xi satisfying exp(Xi)=aliari.

We now show the following theorem which directly implies gOPTO(zbeOPTα(zbeOPT)).

Theorem 8.

Given an LZBE factorization of a string T with zbe factors, we can construct a grammar deriving T of size O(zbeα(zbe)).

Proof.

We begin by constructing an ORPP instance from the given LZBE factorization. The instance consists of a sequence (a1,,azbe) and zbe queries, each corresponding to an LZBE factor. If the i-th factor Fi is a char factor, its query range is simply (li,ri)=(i,i). If Fi is a copy factor referring to FjFk, its query range is defined as (li,ri)=(j,k).

Using Corollary 3, we obtain an SLP of size O(zbeα(zbe)). We then convert this SLP with terminals Σa into a CFG with terminals Σ that generates the original string T. First, we introduce a new start symbol S and add the rule Sa1azbe. Next, for each terminal ai, we replace all its occurrences in the rules as follows.

  1. 1.

    If Fi is a char factor representing a character c, then replace ai with a new nonterminal Xi such that exp(Xi)=c.

  2. 2.

    If Fi is a copy factor, then replace ai with the existing nonterminal Xi such that exp(Xi)=aliari.

The existence of such a nonterminal in the second case is guaranteed by Corollary 3. We can easily see that the size of the new grammar is O(zbeα(zbe)).

Since the start symbol S is expanded as Sa1azbe, it suffices to verify that each nonterminal Xi replacing ai satisfies exp(Xi)=Fi. We prove this by induction on i. If Fi is a char factor representing c, then by the definition of Xi, the nonterminal Xi generates c, and hence exp(Xi)=Fi. Now suppose that Fi is a copy factor, and assume as the induction hypothesis that exp(Xi)=Fi for all 1i<i. The new nonterminal Xi corresponding to Fi is defined by the rule XiXliXri. By the induction hypothesis and the fact that li<ri<i, each Xi with liiri expands to Fi. Therefore, exp(Xi)=exp(Xli)exp(Xri)=FliFri=Fi. By induction, we have exp(Xi)=Fi for all 1izbe, and consequently exp(S)=F1Fzbe=T. Since the size of the constructed grammar is O(zbeα(zbe)), the theorem follows.

Figure 3: Examples of bottom-up computation of val(head(X)) and val(tail(X)). In the left example, the value q2 is computed as q2=val(Q2)=val(tail(Y)head(Z))=val(tail(Y))val(head(Z)).

We note that the lower bound also applies to run-length grammars [21], which are an extension of CFGs allowing for run-length rules of the form XYk. We denote the size of the smallest run-length grammar generating T by grlOPT. Since the string T constructed from the ORPP input is square-free, grlOPT=gOPT holds. Thus, for such T, we have grlOPTΩ(zbegα(zbeg)). This bound is tight even for optimal LZBE factorization; grlOPTO(zbeOPTα(zbeOPT)) also holds for any T since grlOPTgOPT and gOPTO(zbeOPTα(zbeOPT)).

Conversely, there exists a string for which grlOPT is asymptotically smaller than zbeOPT. For example, the string T=𝚊n satisfies grlOPT=O(1) and zbeOPT=O(logn), which implies that zbeOPTΩ(grlOPTlogn) in this case. This bound is tight, since gOPTO(grlOPTlogn) and zbeOPTgOPT together yield zbeOPTO(grlOPTlogn) for any T.

4 Data Structure for Efficient Random Access

In this section, we introduce the following theorem.

Theorem 9.

Given an LZBE factorization =(F1,,Fzbe) of a string T of length n, we can construct, in O(zbe) time and space, a data structure of size O(zbe) that supports random access to any position of T in O(logn) time.

An overview of our data structure is as follows. We employ two central techniques: the interval-biased search tree (IBST) [8] that is a variant of biased search trees [7], and symmetric centroid path decomposition (SymCPD) [13] that is a generalization of the well-known heavy path decomposition [23] for general DAGs. We construct a global IBST over all factors in to simulate jump functions. Additionally, we apply SymCPD to the dependency DAG 𝒟 of an LZBE factorization , which yields a collection of heavy paths with total length O(zbe). For each heavy path, we build a separate IBST to accelerate the traversal along that path.

Throughout this section, we assume the standard RAM model.

4.1 Building Blocks of the Data Structure

4.1.1 Interval-Biased Search Trees

The interval-biased search tree (IBST) [8] is a weighted binary search tree that stores a sequence of consecutive disjoint intervals.

Definition 10 (Interval-Biased Search Tree (IBST) [8, Section 3]).

An interval-biased search tree is a binary tree that stores a collection of disjoint intervals

={[a0,a1),[a1,a2),,[am1,am)},

where a0<a1<<am are strictly increasing integers. Each node in the tree is associated with a single interval from . The tree is defined recursively as follows:

  1. 1.

    The root stores the interval [ai,ai+1) such that the midpoint (ama0)/2 lies within this interval, i.e., (ama0)/2[ai,ai+1).

  2. 2.

    The left child is the IBST constructed over the intervals [a0,a1),,[ai1,ai), and the right child is the IBST constructed over [ai+1,ai+2),,[am1,am).

We denote vi as the node storing [ai,ai+1).

Given a query value q[a0,am), we locate the interval in containing q by traversing the IBST from the root. At each node vi, if q[ai,ai+1), we return it; otherwise, we move to the left child if q<ai, or to the right child if qai+1. Since each child subtree has at most half the total length of its parent, reaching a node vj from vi takes O(logLiLj) steps, where Lk is the total length of intervals in the subtree rooted at vk.

Suppose that two boundaries ai and aj satisfying aiq<aj are known before querying q. In this case, it is not necessary to start the search from the root of the IBST. Instead, we can efficiently locate the interval containing q by exploring only the subtrees rooted at a few specific nodes. We formalize this observation in the following lemma.

Lemma 11.

Let ai<aj be any pair of interval boundaries. By precomputing a constant number of nodes, referred to as hints, associated with the interval [ai,aj), we can locate the interval [ax,ax+1) that contains a query value q[ai,aj) in O(logajaiax+1ax) time. Furthermore, we can precompute hints for h intervals in O(m+h) time.

Proof.

Let lca(vx,vy) denote the lowest common ancestor of nodes vx and vy. We precompute the three hint nodes vc=lca(vi,vj1), vl=lca(vi,vc1), and vr=lca(vc+1,vj1). These three nodes are sufficient to perform the search without starting from the root of the IBST.

The algorithm first checks whether q[ac,ac+1). If so, we have found the target interval. Otherwise, if q[al,ac), we traverse the subtree rooted at vl. If q[ac+1,ar), we traverse the subtree rooted at vr, similar to a standard top-down search. The initial check takes constant time, so we focus on the time complexity for traversing under vl and vr. Consider the case where q[al,ac) and we traverse the subtree of vl. Let as be the starting boundary of the interval covered by the subtree rooted at vl. Then vl covers [as,ac), its left subtree covers [as,al), and its right subtree covers [al+1,ac) (See Figure 4). By the definition of IBST, the interval [al,al+1) stored by vl contains the midpoint (acas)/2 of the total range. Assume, for contradiction, that (ac+as)/2<al. Then vi lie in the left subtree of vl, contradicting the assumption that vl is the lowest common ancestor of vi and vc1. Therefore we must have al(ac+as)/2, which implies 2alacas. Since aialacaj, the length of the subtree is O(ajai). We start the traversal within an interval of length O(ajai) and end in an interval of length ax+1ax, Thus, the traversal time from vl is then O(logajaiax+1ax). An analogous argument applies when traversing under vr. Since the off-line lowest common ancestor problem for a tree with N nodes and Q queries can be solved in O(N+Q) time [14], we can precompute hints for h intervals in O(m+h) time. Given interval boundaries a1,,am, we can construct the IBST in O(m) time [8].

Figure 4: The subtree of the interval-biased search tree rooted at the node vc=lca(vi,vj1), used to locate the interval containing a query value q[ai,aj). The hint nodes vc, vl=lca(vi,vc1), and vr=lca(vc+1,vj1) allow us to restrict the search to subtrees of limited range.

4.1.2 Symmetric Centroid Path Decomposition

The symmetric centroid path decomposition (SymCPD) [13] decomposes a DAG into disjoint paths, extending heavy path decomposition [23] to arbitrary DAGs.

Lemma 12 (Symmetric Centroid Path Decomposition (SymCPD) [13, Lemma 2.1]).

For a DAG 𝒟=V,E, there exists a pair of disjoint edge sets H,LE such that L=EH, satisfying the following conditions:

  1. 1.

    The edge-induced subgraph V,H consists of a set of disjoint paths.

  2. 2.

    Any path in the DAG 𝒟 contains at most 2lgn𝒟 edges from L,

where n𝒟 denotes the number of maximal paths in 𝒟.

An edge in H is called a heavy edge, and a maximal path (including a path consisting of a single node) in the subgraph V,H is called a heavy path. An edge in L is called a light edge. Note that the total length of all heavy paths is bounded by O(|V|), since each vertex has at most one outgoing heavy edge.

We apply this technique to the dependency DAG 𝒟 of an LZBE factorization . Since each maximal path corresponds to a jump sequence and the total number of jump sequences is n, we have n𝒟n, and thus any path in 𝒟 contains at most 2lgn light edges. The next lemma shows that all heavy paths of the dependency DAG 𝒟 can be computed in O(zbe) time.

Lemma 13.

Given an LZBE factorization =(F1,,Fzbe), all heavy paths in the dependency DAG 𝒟 can be computed in O(zbe) time.

Proof.

The original symmetric centroid path decomposition selects an edge (u,v) as a heavy edge if it satisfies the conditions lgns(u)=lgns(v) and lgne(u)=lgne(v), where ns(v) and ne(v) denote the number of maximal paths starting at and ending at node v, respectively. For any node u, the heavy edge among its outgoing edges points to the child with the largest value of ns(v).

Let s1,,szbe and e1,,ezbe be arrays representing ns(Fi) and ne(Fi) for each factor Fi. We initialize all entries to 0, and compute the values as follows: To compute si (number of paths starting from Fi), process i=1,,zbe in increasing order:

  • If Fi is a char factor, set si1.

  • If Fi is a copy factor referring to FjFk, set sii=jksi.

To compute ei (number of paths ending at Fi), process i=zbe,,1 in decreasing order:

  • If ei=0, set ei1.

  • If Fi is a copy factor referring to FjFk, update eiei+ei for all i=j to k.

Both procedures can be implemented in O(zbe) time using a prefix-sum technique.

Once the values of si and ei are computed, we determine, for each copy factor Fi referring to FjFk, the index i[j,k] that maximizes si. This corresponds to solving a range maximum query on each interval [j,k]. All such queries can be answered in total O(zbe) time by reducing them to offline lowest common ancestor (LCA) queries on a Cartesian tree [24] and applying a linear-time offline LCA algorithm [14]. For each resulting candidate edge from Fj to Fi, we then check whether it satisfies the heavy edge condition. Since the number of such candidate edges is O(zbe), this step also runs in linear time. Thus, all heavy edges in the dependency DAG can be computed in O(zbe) time. Once all heavy edges are identified, the corresponding heavy paths can be constructed straightforwardly.

4.2 Our Data Structure

In this subsection, we propose our data structure. It mainly consists of two components: a global IBST to simulate the standard jump function, and heavy-path IBSTs to accelerate sequence of jump operations on the same heavy path.

We begin by simulating the jump function using an IBST. Given an LZBE factorization , we construct an IBST over the set of intervals {[posL(F),posR(F)]F}, which correspond to the positions of the factors in the output string. For each 1izbe, we also precompute the hint nodes described in Lemma 4.1.1 for the interval [srcL(Fi),srcR(Fi)] to accelerate the search. Since both the number of intervals and hints are O(zbe), the data structure can be stored in O(zbe) space. Given a copy factor Fcopy and a relative position 1r|F|, we can compute the jump function jump(F,r) by locating the interval that contains the position srcL(F)+r1. Using the hints for the interval [srcL(F),srcR(F)], we can find the corresponding factor F in O(log|F||F|) time, where F is the next factor in the jump sequence.

We then focus on accelerating a sequence of jump operations on the same heavy path. Let P be a heavy path obtained by applying SymCPD to the dependency DAG 𝒟 of an LZBE factorization. We denote the sequence of factors of P as (Fi1,,Fi). For any 1j<, we introduce two intervals IjL and IjR, defined as follows:

  • IjL=[posL(Fij),posL(Fij)+posL(Fij+1)srcL(Fij)1],

  • IjR=[posR(Fij)+posR(Fij+1)srcR(Fij)+1,posR(Fij)].

For any p[posL(Fij),posR(Fij)](IjLIjR), the position p refers to the next factor on the heavy path; that is, the factor corresponding to jump(rel(p)) is Fij+1. Conversely, for any pIjLIjR, the position p refers to the other factor.

Consider a factor Fis on the heavy path P, a relative position 1rs|Fis|, and the jump sequence starting from (Fis,rs). The beginning of the jump sequence takes the form (Fis,rs),(Fis+1,rs+1),,(Fie,re), where each factor is in the same heavy path P. The sequence terminates either when (Fie,re) is the last element (i.e., e=), or when jump(Fie,re) does not belong to the heavy path P. In the former case, the absolute position abs(Fie,re) lies within [posL(Fie),posR(Fie)], and in the latter case, it lies within either IeL or IeR. We refer to this interval as the exit interval, and (Fie,re) as the exit position of (Fis,rs). Figure 5 illustrates an example of a heavy path and the corresponding exit intervals.

Figure 5: An illustration of a heavy path in the dependency DAG. The path consists of five nodes Fi1 through Fi5, with solid arrows for heavy edges and dotted arrows for light edges. Factors not belonging to this heavy path are shown in gray. The jump sequence from (Fi1,r1), where r1[R5,R2), has exit interval I4R and exit position (Fi4,r4), with r4=R5r1.

We now present the following lemma.

Lemma 14.

For a heavy path P=(Fi1,,Fi), there exists a data structure of size O() that, given a factor Fis and a relative position 1rs|Fis|, computes both the exit position (Fie,re) and the corresponding exit interval I in time O(log|Fis||I|).

Proof.

For 1j, we define Lj and Rj as follows:

Lj ={0if j=1,Lj1+|Ij1L|otherwise,
Rj ={Lj+|Fij|if j=,Rj+1+|IjR|otherwise.

Note that Rj=Lj+|Fij| holds for any j and the sequence L1,,L,R,,R1 is monotonically non-decreasing. Using Lj and Rj, we construct a set of disjoint consecutive intervals ={[L1,L2),,[L1,L),[L,R),[R,R1),,[R2,R1)}.

Given a query position (Fis,rs), we define q=Ls+rs1 and find the interval in that contains q. Let [Lj,Lj+1), [Lj,Rj), or [Rj+1,Rj) be the matching interval. In all cases, we have j=e, and the relative position is given by re=qLj+1=LsLj+rs. The corresponding exit interval is determined as follows:

  • If q[Lj,Lj+1), then the exit interval is IjL.

  • If q[Rj+1,Rj), then the exit interval is IjR.

  • If q[Lj,Rj) (in which case j=e=), then the exit interval is [posL(Fi),posR(Fi)].

To find the interval containing q, we construct an IBST over (excluding empty intervals). Additionally, for each 1j, we precompute the hint nodes for the interval [Lj,Rj) to accelerate the search. Given a query (Fis,rs), we identify the containing interval using the hints. The length of the target interval corresponds to that of the exit intervals. Thus, by Lemma 4.1.1, we can compute the exit position in the claimed time complexity. For each heavy path in , we construct the data structure to support efficient jump operations.

We combine these two data structures to support random access in O(logn) time. Our final structure consists of the global IBST over all factors in and a local IBST P for each heavy path P. In addition, for each factor, we store its associated heavy path and its position within the path to facilitate efficient traversal. We also precompute hint nodes for all IBSTs. For the global IBST , we prepare hints for each interval [posL(F),posR(F)] of every factor F and for all exit intervals. For each heavy-path IBST P, we precompute hints for the intervals [Li,Ri] where 1i<.

Algorithm 1 Algorithm for computing T[p].

The random access algorithm is shown in Algorithm 1. Given a position p, we first locate the factor F1 such that p[posL(F1),posR(F1)], and compute the relative offset r1=pposL(F1)+1 using . In each iteration, we use the IBST P for the heavy path containing Ft to compute the exit position (Ft,rt) and the corresponding exit interval It, using the precomputed hints for Ft. We then determine the next jump target (Ft+1,rt+1) using with the hints for It. The process continues until a char factor is reached.

Each IBST query after the first uses a precomputed hint and runs in O(log(X/Y)) time, where X is the length of the hint interval and Y is the length of the interval found in the current query. By construction, the hint interval for each query is set to match the length of the interval found in the previous query. Thus, each query takes O(logtt+1) time, where t is the length of the interval found at the t-th query. Due to the structure of LZBE, each jump transitions to a factor no longer than the current one. Consequently, the sequence of interval lengths 1,,k+1 is non-increasing, where k is the total number of jumps. Furthermore, since a jump sequence corresponds to a path in the dependency DAG, k is bounded by the number of heavy paths and light edges traversed along this path. By properties of heavy path decomposition, this gives k=O(logn). Therefore, applying the telescoping sum technique, the total query time is bounded by t=1kO(logtt+1)=O(k+log1k+1)=O(logn). The total number of intervals and hints used in both the global IBST and the heavy path IBSTs is O(zbe). Hence, the overall space complexity is O(zbe), and all components can be constructed in O(zbe) time. Since the mapping between factors and heavy paths can also be computed within the same bounds, the resulting data structure satisfies Theorem 9.

5 Linear-time Computation of the Greedy LZBE Factorization

In this section, we present the following theorem.

Theorem 15.

Given a string T of length n, the greedy LZBE factorization of T can be computed in O(n) time.

We assume the word-RAM model with word size Ω(logn), and a linearly-sortable alphabet.

Given a string T and its greedy LZBE factorization of a prefix T[1,p]=F1Fk, we define the extended factors E1,,Ek as follows:

Ei={FiFi+1if Fi{E1,,Ei1},Fiotherwise.

If the last factor Ek is equal to some earlier extended factor (i.e., Ek{E1,,Ek1}), we do not define Ek. We begin by establishing several combinatorial properties of the extended factors that arise in the greedy LZBE factorization.

Lemma 16.

No string appears more than twice as an extended factor.

Proof.

We prove this lemma by showing that any two non-consecutive extended factors (i.e., those with |ij|2) must be distinct. Assume for contradiction that Ei=Ej for some i+1<j. If Ej=Fj, then Ei=Ej implies that Ej appears in {E1,,Ej1}, contradicting the definition of extended factors. Therefore, it must be that Ej=FjFj+1. In that case, since Ei=Ej=FjFj+1 appears earlier than posL(Fj) as a consecutive sequence of factors, choosing Fj as the next factor violates the longest-greedy condition, as Ei would have been the longer valid choice. Thus, non-consecutive extended factors must be distinct.

Lemma 17.

Let F1Fk be the greedy LZBE factorization of T[1,p]. If Fk+1 is a copy factor and its leftmost valid source occurrence is FiFj, then Fk+1 begins with Ei.

Proof.

If i<j, then Fk+1 begins with FiFi+1=Ei, so the claim holds. If Ei=Fi, the claim also clearly holds. It remains to consider the case where Ei=FiFi+1 and Fk+1=Fi. In this case, Fi already appears as an earlier extended factor. Thus, Fi would not be chosen as the start of a new factor since the algorithm selects the leftmost valid occurrence. Therefore, this case does not occur, and the claim holds.

We begin by describing a simple algorithm that does not provide strong theoretical guarantees. This algorithm maintains a trie representing all extended factors computed so far. Suppose we have already computed the factorization F1Fk for the prefix T[1,p]. To determine the next factor starting at position p+1, we follow the path in the trie along the suffix T[p+1,n]. For each extended factor Ei on this path, we attempt to extend Ei to the longest prefix of T[p+1,n] that can be expressed as a concatenation FiFj for some ij. This is done by computing the longest common prefix (LCP) length d between T[p+1,n] and T[posL(Fi),n], and locating the factor containing the position posL(Fi)+d. Each such computation yields a candidate factor FiFj, and we select the longest among them as Fk+1. We can answer LCP queries in constant time by using an LCP array [19] together with a range minimum data structure [6], both of which can be constructed in O(n) time and space.

Although conceptually simple, this approach offers no strong time bound. In the worst case, the path traversal for computing Fk+1 may traverse far beyond the length of the factor eventually selected. A straightforward analysis shows that the running time becomes O(n2), and it is unclear whether a faster guarantee can be obtained for this method. We therefore turn to a refined approach that achieves an O(n) running time.

To obtain a linear time algorithm, we replace the extended factor trie with the suffix tree ST [25] of T and augment it with additional structures. We construct a Weighted Level Ancestor (WLA) structure [5] and an incremental Nearest Marked Ancestor (NMA) structure [3] on the ST. Together, these allow us to locate the locus of any substring and to maintain marks on the loci with amortized constant time updates and queries. All components can be constructed in O(n) time and stored in O(n) space. In the algorithm, each extended factor Ei is represented by a mark at the corresponding locus. With this refinement, enumerating candidate extended factors is replaced by walking up from the leaf representing the suffix T[p+1,n] and repeatedly computing NMAs. For each retrieved mark corresponding to an extended factor, we compute the LCP value between the suffix and extendend factor, and obtain a candidate of the next factor. After selecting Fk+1, we insert marks for the newly created extended factors, and the NMA structure maintains them.

We now analyze the running time of this algorithm. Consider computing Fk+1 starting from the position p+1, and let d be the maximum depth of any marked locus on the path representing T[p+1,n]. Since each locus can carry at most two marks by Lemma 5, the path contains at most 2d marks in total. The deepest mark on the path corresponds to an extended factor that matches a prefix of T[p+1,n] of length d, which implies that the length of the next factor Fk+1 is at least d. Consequently, the number of candidate extended factors that must be examined is O(|Fk+1|). Because each LCP, WLA, NMA, and marking operation runs in amortized constant time, computing Fk+1 and updating the data structures takes amortized O(|Fk+1|) time. Since the total length of all factors is n, summing over all iterations shows that the greedy LZBE factorization can be computed in overall O(n) time.

6 Conclusion

We introduced LZ-Begin-End (LZBE), a new LZ-like factorization where every copy factor refers to a contiguous sequence of preceding factors. On the structural side, we showed that any CFG of size g can be converted into an LZBE factorization of size at most g, implying zbeOPTgOPT. We further established a separation in the other direction, proving that there exist strings for which gOPTΩ(zbegα(zbeg)). Complementing this lower bound, we gave an O(zbeOPTα(zbeOPT)) upper bound on the grammar size, and analogous statements for run length grammars. On the algorithmic side, we presented a linear time algorithm that computes the greedy LZBE factorization. We also designed a random access index that supports access in O(logn) time using O(zbe) space and build time, by combining interval biased search trees with symmetric centroid path decomposition over the dependency DAG.

References

  • [1] Jyrki Alakuijala and Zoltan Szabadka. Brotli compressed data format. RFC, 7932:1–128, 2016. doi:10.17487/RFC7932.
  • [2] Noga Alon and Baruch Schieber. Optimal preprocessing for answering on-line product queries. CoRR, abs/2406.06321, 2024. doi:10.48550/arxiv.2406.06321.
  • [3] Stephen Alstrup, Thore Husfeldt, and Theis Rauhe. Marked ancestor problems. In 39th Annual Symposium on Foundations of Computer Science, FOCS ’98, November 8-11, 1998, Palo Alto, California, USA, pages 534–544. IEEE Computer Society, 1998. doi:10.1109/SFCS.1998.743504.
  • [4] Hideo Bannai, Mitsuru Funakoshi, Diptarama Hendrian, Myuji Matsuda, and Simon J. Puglisi. Height-bounded Lempel-Ziv encodings. In Timothy M. Chan, Johannes Fischer, John Iacono, and Grzegorz Herman, editors, 32nd Annual European Symposium on Algorithms, ESA 2024, September 2-4, 2024, Royal Holloway, London, United Kingdom, volume 308 of LIPIcs, pages 18:1–18:18. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2024. doi:10.4230/LIPIcs.ESA.2024.18.
  • [5] Djamal Belazzougui, Dmitry Kosolobov, Simon J. Puglisi, and Rajeev Raman. Weighted ancestors in suffix trees revisited. In Pawel Gawrychowski and Tatiana Starikovskaya, editors, 32nd Annual Symposium on Combinatorial Pattern Matching, CPM 2021, July 5-7, 2021, Wrocław, Poland, volume 191 of LIPIcs, pages 8:1–8:15. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2021. doi:10.4230/LIPIcs.CPM.2021.8.
  • [6] Michael A. Bender and Martin Farach-Colton. The LCA problem revisited. In Gaston H. Gonnet, Daniel Panario, and Alfredo Viola, editors, LATIN 2000: Theoretical Informatics, 4th Latin American Symposium, Punta del Este, Uruguay, April 10-14, 2000, Proceedings, volume 1776 of Lecture Notes in Computer Science, pages 88–94. Springer, 2000. doi:10.1007/10719839_9.
  • [7] Samuel W. Bent, Daniel Dominic Sleator, and Robert Endre Tarjan. Biased search trees. SIAM J. Comput., 14(3):545–568, 1985. doi:10.1137/0214041.
  • [8] Philip Bille, Gad M. Landau, Rajeev Raman, Kunihiko Sadakane, Srinivasa Rao Satti, and Oren Weimann. Random access to grammar-compressed strings and trees. SIAM J. Comput., 44(3):513–539, 2015. doi:10.1137/130936889.
  • [9] Bernard Chazelle and Burton Rosenberg. The complexity of computing partial sums off-line. Int. J. Comput. Geom. Appl., 1(1):33–45, 1991. doi:10.1142/S0218195991000049.
  • [10] Ferdinando Cicalese and Francesca Ugazio. Hardness and approximability of bounded access lempel ziv coding. Inf. Comput., 307:105366, 2025. doi:10.1016/J.IC.2025.105366.
  • [11] Yann Collet and Murray S. Kucherawy. Zstandard compression and the application/zstd media type. RFC, 8478:1–54, 2018. doi:10.17487/RFC8478.
  • [12] Peter Deutsch. GZIP file format specification version 4.3. RFC, 1952:1–12, 1996. doi:10.17487/RFC1952.
  • [13] Moses Ganardi, Artur Jez, and Markus Lohrey. Balancing straight-line programs. J. ACM, 68(4):27:1–27:40, 2021. doi:10.1145/3457389.
  • [14] Dov Harel. A linear time algorithm for the lowest common ancestors problem (extended abstract). In 21st Annual Symposium on Foundations of Computer Science, Syracuse, New York, USA, 13-15 October 1980, pages 308–319. IEEE Computer Society, 1980. doi:10.1109/SFCS.1980.6.
  • [15] Dominik Kempa and Barna Saha. An upper bound and linear-space queries on the lz-end parsing. In Joseph (Seffi) Naor and Niv Buchbinder, editors, Proceedings of the 2022 ACM-SIAM Symposium on Discrete Algorithms, SODA 2022, Virtual Conference / Alexandria, VA, USA, January 9 - 12, 2022, pages 2847–2866. SIAM, 2022. doi:10.1137/1.9781611977073.111.
  • [16] Sebastian Kreft and Gonzalo Navarro. On compressing and indexing repetitive sequences. Theor. Comput. Sci., 483:115–133, 2013. doi:10.1016/J.TCS.2012.02.006.
  • [17] Abraham Lempel and Jacob Ziv. On the complexity of finite sequences. IEEE Trans. Inf. Theory, 22(1):75–81, 1976. doi:10.1109/TIT.1976.1055501.
  • [18] Zsuzsanna Lipták, Francesco Masillo, and Gonzalo Navarro. BAT-LZ out of hell. In Shunsuke Inenaga and Simon J. Puglisi, editors, 35th Annual Symposium on Combinatorial Pattern Matching, CPM 2024, June 25-27, 2024, Fukuoka, Japan, volume 296 of LIPIcs, pages 21:1–21:17. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2024. doi:10.4230/LIPIcs.CPM.2024.21.
  • [19] Udi Manber and Eugene W. Myers. Suffix arrays: A new method for on-line string searches. SIAM J. Comput., 22(5):935–948, 1993. doi:10.1137/0222058.
  • [20] Gonzalo Navarro. Indexing highly repetitive string collections, part I: repetitiveness measures. ACM Comput. Surv., 54(2):29:1–29:31, 2022. doi:10.1145/3434399.
  • [21] Takaaki Nishimoto, Tomohiro I, Shunsuke Inenaga, Hideo Bannai, and Masayuki Takeda. Fully dynamic data structure for LCE queries in compressed space. In Piotr Faliszewski, Anca Muscholl, and Rolf Niedermeier, editors, 41st International Symposium on Mathematical Foundations of Computer Science, MFCS 2016, August 22-26, 2016 - Kraków, Poland, volume 58 of LIPIcs, pages 72:1–72:15. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2016. doi:10.4230/LIPIcs.MFCS.2016.72.
  • [22] Wojciech Rytter. Application of Lempel-Ziv factorization to the approximation of grammar-based compression. Theor. Comput. Sci., 302(1-3):211–222, 2003. doi:10.1016/S0304-3975(02)00777-6.
  • [23] Daniel Dominic Sleator and Robert Endre Tarjan. A data structure for dynamic trees. J. Comput. Syst. Sci., 26(3):362–391, 1983. doi:10.1016/0022-0000(83)90006-5.
  • [24] Jean Vuillemin. A unifying look at data structures. Commun. ACM, 23(4):229–239, 1980. doi:10.1145/358841.358852.
  • [25] Peter Weiner. Linear pattern matching algorithms. In 14th Annual Symposium on Switching and Automata Theory, Iowa City, Iowa, USA, October 15-17, 1973, pages 1–11. IEEE Computer Society, 1973. doi:10.1109/SWAT.1973.13.
  • [26] Jacob Ziv and Abraham Lempel. A universal algorithm for sequential data compression. IEEE Trans. Inf. Theory, 23(3):337–343, 1977. doi:10.1109/TIT.1977.1055714.

Appendix A A Lower Bound on the Approximation Ratio of Greedy to Optimal LZBE Factorization

Theorem 18.

There exists a family of binary strings such that the greedy LZBE factorization produces asymptotically twice as many factors as some alternative valid LZBE factorization.

Proof.

For any positive integer m>1, define the strings A, B, Ai, and Ti,j over the alphabet {a,b} for 0i<m and 0j<m as follows:

A =a2m+1,
B =b2m+1b,
Ai =k=mi+1ma2k,
Ti,j =AB(i=1i1j=1m1Aib2j+1b)(j=1jAib2j+1b),

where i=xySi denotes the concatenation of Sx,,Sy, and is defined as the empty string if x>y. Note that Ti,j can be obtained by appending Aib2j+1b to the end of Ti,j1, and that Ti,m1=Ti+1,0 hold. The string Tm1,m1 gives a lower bound.

We first analyze the greedy LZBE factorization of Ti,j by induction. The base case is T0,0=AB, which is parsed as:

a|a|a2|a4||a2m|b|b|b2|b4||b2m|b.

When constructing the factorization of Ti,j from that of Ti,j1, all factors of Ti,j1 except the last one remain unchanged. We prove the following:

  • If j=1, the greedy factorization of Ti,j is obtained by appending two new factors: Aib2j+1 and b.

  • If j>1, the greedy factorization of Ti,j is obtained by replacing the last factor b of Ti,j1 with bAib2j, and then appending two new factors: b2j and b.

From this, we observe that the last factor of Ti,j is always b for all 1im and 0j<m. We first consider the case j=1. Here, Ti,j1=Ti,0=Ti1,m1, and the appended string is Aib4b. Since the length of Ai increases with i, the substring Ai does not appear in Ti,j1, except possibly as part of A. Thus, the last factor b of Ti,j1 remains unchanged in Ti,j. We can take Aib4 as a concatenation of factors by referring to Ai from the suffix of A and b4 from the prefix of B. However, we cannot take Aib5 as a factor, because the factorization of B follows the structure b|b|b2|b4|, and hence only substrings like Aib2x can be taken as consecutive factors. Thus, the factorization for this case is correct.

Now consider the case j>1. The suffix of Ti,j has the form:

bAib2jbAib2j+1b.

By the induction hypothesis, the previous two factors in the greedy factorization of Ti,j1 are b and Aib2j when j=2, and bAib2j1 and b2j1 when j>2. Therefore, we now need to determine the factorization for the new portion bAib2j+1b. In this case, we can take bAib2j by referring to the two previous consecutive factors. However, we cannot take a longer match, as the substring bAib2j appears nowhere else in the factorized part of Ti,j except in this location. The remaining suffix b2jb includes a factor b2j from B, but we cannot take b2jb as a concatenation of existing factors. Hence, the greedy factorization proceeds correctly in this case as well. Finally, we count the total number of factors. The base case T0,0 contains 2m+5 factors. The difference in the number of factors between Ti,j1 and Ti,j is always 2. Thus, the total number of factors in the greedy factorization of Tm1,m1 is:

2m+5+2(m1)(m1)=2m22m+7.

We now give an LZBE factorization of Tm1,m1 that produces a smaller number of factors. We parse the prefix T0,0=AB of Tm1,m1 as:

a|a|a2|a4||a2m|b|b|b|b2|b4||b2m.

The only difference from the greedy factorization lies in the part of B. This factorization allows substrings of the form Aib2j+1b to be represented as a concatenation of multiple existing factors for all 1i<m and 1j<m. Thus, we can construct the factorization of Ti,j recursively by concatenating the factorization of Ti,j1 with a single new factor Aib2j+1b. The total number of factors in this factorization of Tm1,m1 is:

2m+5+(m1)(m1)=m2+6.

Therefore, as m, the ratio between the number of factors in the greedy factorization and in this factorization approaches 2 (See Figure 6).

Figure 6: Illustration of the greedy LZBE factorization and a smaller LZBE factorization of the string Tm1,m1. In the smaller factorization, the substring A1b4b=a2mb5 (dotted lines) is selected as a single factor.

Although we have constructed a family of strings for which the ratio between the greedy LZBE factorization and a smaller one approaches 2, we have not found any example where the ratio between the greedy and the optimal factorization exceeds 2. This resembles the case of LZ-End, for which a 2-approximation is also conjectured. Motivated by this parallel, we conjecture that the greedy LZBE factorization achieves a 2-approximation; that is, for any string T, we have zbeg2zbeOPT.