arXiv:2611.08671cs.DSNov 2026

Manuscript Offprint

arXiv:2611.08671

Greedy Byte-Pair Encoding Achieves at Least 0.361 of the Optimal Compression

Kundan Baliga, Aiden Xie, Aditya Byju

Abstract

Byte-Pair Encoding (BPE) builds a tokeniser by repeatedly merging a most frequent adjacent pair of symbols; its utility is the total reduction in string length achieved by kk merges. It was known that this greedy rule achieves at least a third of the optimal reduction. We prove that it always achieves at least 0.361 of the optimal reduction in string length, for every string, every budget and every tie-breaking rule; this is the first improvement of the bound one third. We also explain why one third was a barrier: the pair-packing relaxation behind it is tight, so a better bound must use more of the optimum's structure. When greedy destroys three of the optimum's merge points at once, one of them can usually be moved next door, because all copies of a rule of the optimum look alike; the remaining cases are paid for later. Along the way we determine the worst-case ratio for two merges exactly, bound it for three, and isolate a single inequality that would settle the problem.

Code for the finite checks in Appendix B: Zenodo, doi:10.5281/zenodo.23970171.

1 Introduction

Byte-Pair Encoding [2, 7] builds the vocabularies of most current language models, and it is a greedy algorithm of the simplest kind. Given a string ss and a budget kk, it finds a most frequent adjacent pair of symbols, replaces all of its occurrences by a fresh symbol, and repeats this kk times. Each replacement shortens the string by one, and the total shortening is the utility of the merge sequence. How much shorter could the string have become with kk well-chosen merges? Computing the optimum is NP-hard [8], even over bounded alphabets [3], and it is APX-complete [4]: unless P = NP, no polynomial-time algorithm approximates it within every constant factor. So the natural question is how well the greedy rule approximates it.

Kozma and Voderholzer [4, 5] formalised this question. Writing BPE(s,k)(s,k) for greedy's utility and OPT(s,k)(s,k) for the optimum, they proved

13≤ρ:=inf⁡s,kBPE(s,k)OPT(s,k)≤1−e−22≈0.4323.\frac{1}{3} \leq \rho := \inf_{s,k} \frac{\mathrm{BPE}(s,k)}{\mathrm{OPT}(s,k)} \leq \frac{1 - e^{-2}}{2} \approx 0.4323.

The lower bound comes from a charging argument: each greedy replacement is charged for the merge points of the optimum it destroys, counted through a pair-packing relaxation, which only records, for each rule, a set of disjoint occurrences of one letter pair; the upper bound, in the extended version [5], comes from a family of instances in which the budget kk grows without bound. The same upper bound was obtained independently by Yang [9], who also proved that BPE achieves at least (1−(1−2/k)k)/2(1-(1-2/k)^k)/2 of every pair encoding whose tokens have length at most three, so that (1−e−2)/2(1-e^{-2})/2 is exact against such encodings. Against the unrestricted optimum the lower bound remained 1/31/3, and Yang identifies the obstacle: inside a long token of the optimum, one greedy replacement can destroy three of its merge points rather than two [9, Section 7].

Our results. We write g1≥g2≥…g_1 \geq g_2 \geq \ldots for the utilities of greedy's successive merges and Gi=g1+⋯+giG_i = g_1 + \cdots + g_i.

  • Greedy beats one third (Theorem 11). For every string, every budget and every tie-breaking rule, BPE(s,k)≥0.361⋅OPT(s,k)(s,k) \geq 0.361 \cdot \mathrm{OPT}(s,k). The proof is elementary (Section 4), apart from a finite certification in exact rational arithmetic (Appendix B). Its first layer alone gives 0.3478 (Corollary 4).

  • Why one third was stuck (Theorem 16). The pair-packing relaxation used for the bound 1/31/3 cannot certify more: there are instances on which greedy achieves only a fraction tending to 1/31/3 of the packing. Any improvement must therefore use more of the optimum's structure than a packing records.

  • Small budgets (Section 5). With two merges the worst-case ratio is exactly 3/43/4. With three it is at most 7/127/12, by an explicit family checkable by hand.

  • One inequality would settle the problem (Section 6). If greedy's replacements always cost the optimum at most two units each, where a destroyed merge point may be counted again at a neighbouring gap, that is, if OPT≤2Gi+kgi+1\mathrm{OPT} \leq 2G_i + k g_{i+1}, then ρ=(1−e−2)/2\rho = (1 - e^{-2})/2.

The technique. The structural fact we add to the Kozma–Voderholzer argument is rule determinism: every copy of a rule of the optimum has the same tree. The KV charging pays three units of the optimum for a greedy replacement whenever it destroys the optimum's merge points on both sides and in the middle. We show that in such an event the destroyed central merge can usually be moved to the next gap, where by rule determinism it counts as an occurrence of a pair that is the same for all copies of the rule; when it cannot, its parent's position becomes a ghost whose pair is again fixed by a rule. This reduces the cost to 2.5 units per replacement, at the price of a weaker last term: the term kgi+1k g_{i+1} of the KV inequality becomes 2kgi+12k g_{i+1}. Interleaving the two per-step inequalities gives 0.3478. The term 2kgi+12k g_{i+1} counts all moved nodes and ghosts that might still be alive. We show that they form groups of one type each, and that whenever greedy glues a gap that carries an object, the object's whole group disappears and never returns. So the last term shrinks over the run, as the number of rules still counted does in the KV argument, and the constant rises to 0.361.

Related work. The merge process is Re-Pair [6] in grammar compression, where the measure of interest is the size of the grammar rather than the utility; [4] explain why the two behave differently. Zouhar et al. [10] gave the first formal treatment of BPE as an optimisation problem and related greedy's performance to a curvature parameter of the objective, without worst-case bounds. In a companion paper [1] we analyse a different greedy tokeniser, GreedTok, whose objective is a coverage function.