The Trie Measure, Revisited
Jarno N. Alanko, Ruben Becker, Davide Cenzato, Travis Gagie, Sung-Hwan Kim, Bojana Kodric, Nicola Prezza
TL;DR
This work addresses minimizing the trie measure for encoding sequences of integer sets by exploring structured prefix-free encodings. It develops two exact strategies for shifts: (i) an $O(u+N\log u)$-time algorithm based on a simple array representation, and (ii) an $O(N\log^2 u)$-time algorithm using a DAG-compressed segment tree, both exploiting a periodic structure in the shift; and two encodings for order-preserving (prefix-free) representations via a Knuth-like dynamic programming approach that yields an optimal ordered encoding in $O(N+u^3)$ time. It further extends the ordered encoding to shifted-ordered encodings by doubling the domain and applying the same DP framework, preserving the cubic-time bound. The paper provides practical implementations and experimental evidence on multiple real-world datasets, showing that shifted-ordered encodings can markedly outperform individual shifted or ordered encodings and that typical shifts are near-optimal on practice. These results inform space-efficient encoding choices for data-structure applications that rely on tries and set-sequences, including subset wavelet trees and offline set-intersection strategies.
Abstract
In this paper, we study the following problem: given $n$ subsets $S_1, \dots, S_n$ of an integer universe $U = \{0,\dots, u-1\}$, having total cardinality $N = \sum_{i=1}^n |S_i|$, find a prefix-free encoding $enc : U \rightarrow \{0,1\}^+$ minimizing the so-called trie measure, i.e., the total number of edges in the $n$ binary tries $\mathcal T_1, \dots, \mathcal T_n$, where $\mathcal T_i$ is the trie packing the encoded integers $\{enc(x):x\in S_i\}$. We first observe that this problem is equivalent to that of merging $u$ 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 $0\le a < u$, this encoding sends each $x \in U$ to $(x + a) \mod u$, interpreted as a bit-string of $\log u$ bits. We develop the first efficient algorithms that find the value of $a$ minimizing the trie measure when this encoding is used. Our two algorithms run in $O(u + N\log u)$ and $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+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.
