cs.DSNov 10, 2026

Pair-Merge Tokenisation Is Hard to Approximate on Binary Strings and Strongly NP-Hard on Unary Datasets

Authors: Kundan Baliga, Aiden Xie, Aditya Byju

Organizations: University of Illinois Urbana-Champaign · Georgia Institute of Technology

Abstract

Tokenisers such as Byte-Pair Encoding (BPE) shorten text by repeatedly merging an adjacent pair of symbols into a new one; fewer tokens mean less computation. We ask whether an efficient algorithm can choose kk merges that leave a string of length nn almost as short as possible; doing nothing is already within a factor nn. We prove that, unless P = NP, no polynomial-time algorithm comes within a factor c n/log⁡nc\,n/\log n, for some constant c>0c>0, already for one binary string and for BPE-style merges that replace every occurrence. The key idea is that kk merges form a grammar with kk rules: a vertex-cover gap becomes a grammar-size gap, which we amplify with relabelled copies, encode in binary and realise with explicit merges. For merges that may skip occurrences, a simple algorithm achieves O(n/log⁡log⁡n)O(n/\log\log n), and no Karp reduction can prove hardness beyond order n/log⁡nn/\log n unless coNP ⊆\subseteq NP/poly. Over a one-letter alphabet, both tokenisation problems left open by Kastreva et al. are strongly NP-complete on datasets with repeated strings.

Figures & tables

Explore similar work

CardsList
  1. Tokenization: Hardness and Bicriteria Approximation Algorithms

    Nov 11, 2026Atieh Bastan, Xiaoling He, A. Pavan +1TokenizationApproximation Algorithms

  2. Greedy Byte-Pair Encoding Achieves 0.391 of the Optimum, Past the One-Third Barrier for Packing-Based Analyses

    Nov 5, 2026Kundan Baliga, Aiden Xie, Aditya ByjuByte-Pair EncodingLossless Data Compression

  3. Theoretical Analysis of Byte-Pair Encoding

    Nov 13, 2024László Kozma, Johannes VoderholzerByte-Pair EncodingSubword Tokenization