English

The Trie Measure, Revisited

Data Structures and Algorithms 2025-04-16 v1

Abstract

In this paper, we study the following problem: given nn subsets S1,,SnS_1, \dots, S_n of an integer universe U={0,,u1}U = \{0,\dots, u-1\}, having total cardinality N=i=1nSiN = \sum_{i=1}^n |S_i|, find a prefix-free encoding enc:U{0,1}+enc : U \rightarrow \{0,1\}^+ minimizing the so-called trie measure, i.e., the total number of edges in the nn binary tries T1,,Tn\mathcal T_1, \dots, \mathcal T_n, where Ti\mathcal T_i is the trie packing the encoded integers {enc(x):xSi}\{enc(x):x\in S_i\}. We first observe that this problem is equivalent to that of merging uu sets with the cheapest sequence of binary unions, a problem which in [Ghosh et al., ICDCS 2015] is shown to be NP-hard. Motivated by the hardness of the general problem, we focus on particular families of prefix-free encodings. We start by studying the fixed-length shifted encoding of [Gupta et al., Theoretical Computer Science 2007]. Given a parameter 0a<u0\le a < u, this encoding sends each xUx \in U to (x+a)modu(x + a) \mod u, interpreted as a bit-string of logu\log u bits. We develop the first efficient algorithms that find the value of aa minimizing the trie measure when this encoding is used. Our two algorithms run in O(u+Nlogu)O(u + N\log u) and O(Nlog2u)O(N\log^2 u) time, respectively. We proceed by studying ordered encodings (a.k.a. monotone or alphabetic), and describe an algorithm finding the optimal such encoding in O(N+u3)O(N+u^3) time. Within the same running time, we show how to compute the best shifted ordered encoding, provably no worse than both the optimal shifted and optimal ordered encodings. We provide implementations of our algorithms and discuss how these encodings perform in practice.

Keywords

Cite

@article{arxiv.2504.10703,
  title  = {The Trie Measure, Revisited},
  author = {Jarno N. Alanko and Ruben Becker and Davide Cenzato and Travis Gagie and Sung-Hwan Kim and Bojana Kodric and Nicola Prezza},
  journal= {arXiv preprint arXiv:2504.10703},
  year   = {2025}
}

Comments

To appear at CPM 2025

R2 v1 2026-06-28T22:58:23.597Z