arXiv:2611.12348cs.DSNov 2026

Manuscript Offprint

arXiv:2611.12348

How Hard Is Tokenisation? Algorithms and Complexity Beyond NP-Hardness

Andrei Robert Ion, Rares Mateiu, Adrian Miclaus, Alexandru Popa

Abstract

Given a collection of strings and a vocabulary budget, how well can we minimize its total token count, and how does the answer change with the tokenisation model? For binary direct tokenisation, previous work proved APX-hardness but left constant-factor approximability unresolved [1]. We rule out every polynomial-time M1−εM^{1-\varepsilon} approximation, for fixed ε>0\varepsilon > 0, unless P=NPP = NP, even on distinct equal-length strings with K=m−1K = m-1. Here MM is the total input length and mm is the number of input strings. We complement this lower bound with a deterministic polynomial-time O(M/log⁡M)O(M/\log M) approximation algorithm and stronger bounds for selected vocabulary budgets. For the different objective of maximizing compression savings, GreedTok was shown to attain a constant fraction of the optimum on unrestricted alphabets [2]; we establish a deterministic EPTAS for direct savings on every fixed alphabet and analyze greedy selection by true marginal gains. For exact optimization, we give a binary direct algorithm running in 2O(nlog⁡log⁡n/log⁡n)2^{O(n \log \log n / \log n)} poly(II) time, where nn is the total length of the distinct input strings and II is the input encoding length. Finally, we resolve two unary merge-model hardness questions left by the bounded-alphabet study [1]: standard unary bottom-up tokenisation is APX-hard, and unary optimal pair encoding is strongly NP-complete, strengthening the previously known weak hardness.

Keywords: tokenisation, vocabulary optimisation, approximation algorithms, APX-hardness, exact exponential algorithms, parameterized complexity.

1 Introduction