---
title: Range-to-Prefix Conversion Algorithm
url: https://www.emergentmind.com/topics/range-to-prefix-conversion-algorithm
type: topic
---

# Range-to-Prefix Conversion Algorithm

Searching arXiv for the cited papers to ground the article in current records.
Range-to-prefix conversion denotes a family of reductions in which a range query is recast as a bounded number of prefix queries on a derived representation. In current arXiv usage, the term has two principal technical realizations. In succinct string indexing, lexicographic-range queries on the suffix array of a text $T$ are reduced to prefix-select queries on a sequence $W$ of short binary strings, yielding an equivalence between suffix-array functionality and prefix-query structures up to an additive $O(\log\log n)$ query-time term [2510.19815]. In approximate range filtering, an integer interval $[\ell,r]$ is converted into a minimum-cardinality family of dyadic intervals, each represented by a binary prefix, so that range lookups become a small number of prefix probes [2207.04789]. A closely related dual construction converts colored-prefix queries into colored-range queries in the external-memory model, showing that prefix/range conversion is a bidirectional design pattern rather than a single domain-specific routine [1104.3084].

## 1. Formal query models

In the suffix-array setting, the source problem is the lexicographic-range query. Given a text $T \in [0..\sigma)^n$, one builds a data structure on $T$ of size $S(n)$, and on input two patterns $P_1,P_2 \in [0..\sigma)^*$ returns
$$
\mathrm{LexRange}_T(P_1,P_2) \coloneqq \{\, SA_T[i] : i \in (\mathrm{RangeBeg}_T(P_1)\ldots \mathrm{RangeBeg}_T(P_2)] \,\},
$$
where
$$
\mathrm{RangeBeg}_T(P)=|\{\, j : T[j\ldots n]\prec P \,\}|.
$$
Equivalently, one may ask for reporting all positions whose suffixes lie in the half-open interval $[P_1,P_2)$ in lexicographic order, or just its minimum. The target problem is prefix-select on a sequence $W[1..m]$ of $m$ binary strings of length exactly $\ell = 1+\lfloor \log m \rfloor$; given a query bit-pattern $X \in \{0,1\}^{\le \ell}$ and a rank $r \in [1..\mathrm{prefix}_W(m,X)]$, the query returns
$$
\mathrm{select}_W(X,r),
$$
the $r$-th smallest $j \in [1..m]$ such that $X$ is a prefix of $W[j]$ [2510.19815].

A second formulation arises in integer range filtering. There the universe is
$$
U=\{0,1,\ldots,2^d-1\},
$$
and the task is to cover a query interval $I=[\ell,r]\subseteq U$ exactly by a small collection of dyadic intervals. Each dyadic interval corresponds to a binary prefix of length $d-k$ for some $k$, so the range query is transformed into a prefix set. The required cover is exact, and the number of prefixes is minimized by the standard greedy decomposition [2207.04789].

These formulations differ in object type—suffix-array intervals versus integer intervals—but they share a common abstraction: a range is replaced by prefix descriptors whose order-theoretic structure is easier to index or hash.

## 2. Embedded sequence construction and occurrence mapping

The core construction underlying the string-theoretic reduction starts from a sequence $W[1..m]$ of bit-strings of length $\ell = 1+\lfloor \log m \rfloor$. Let $k=\ell$. For $i=1,\ldots,m$, define
$$
\mathrm{block}_i = \mathrm{reverse}(W[i]) \cdot '\$' \cdot \mathrm{bin}(i-1,k),
$$
where `$\$$` is a new separator symbol greater than any bit, and $\mathrm{bin}(x,k)$ is the length-$k$ binary encoding of $x$ with leading zeros. The text is then
$$
T=\mathrm{block}_1 \cdot \mathrm{block}_2 \cdot \cdots \cdot \mathrm{block}_m.
$$
Its length is
$$
|T| = m\cdot (\ell+1+k)=\Theta(m\log m).
$$
The construction embeds the prefix structure of $W$ into the suffix-array geometry of $T$ [2510.19815].

For a query prefix $X$ with $|X|\le \ell$, let $q=\mathrm{prefix}_W(m,X)$, and let $p_i$ denote the $i$-th index of $W$ carrying $X$ as a prefix. The key observation is
$$
\mathrm{Occ}_T(\mathrm{reverse}(X)\cdot '\$')=
\{\, (p_i-1)\cdot (\ell+1+k)+(|X|+1) : i=1,\ldots,q \,\}.
$$
These occurrences appear in the same order in $T$ as the increasing indices $p_i$. If
$$
\alpha = \mathrm{RangeBeg}_T(\mathrm{reverse}(X)\$), \qquad \beta = \ell+1+k,
$$
then for any $1\le i\le q$,
$$
p_i = \left\lceil \frac{SA_T[\alpha+i]}{\beta} \right\rceil .
$$
This occurrence mapping is the structural bridge between suffix-array intervals and prefix-select answers.

The same construction also supports the converse viewpoint. The summary states that any lex-range query on $SA_T$ can be answered by one $\mathrm{RangeBeg}$ call plus repeated prefix-select queries on $W$, while any prefix-select can be implemented by two $\mathrm{RangeBeg}$ calls and one small-range access on $SA_T$. The reduction is therefore bidirectional rather than merely one-way.

## 3. Answering lexicographic ranges through prefix-select

The operational form of the range-to-prefix reduction assumes that one can answer $\mathrm{RangeBeg}_T(P)$ in $O(\log\log n)$ time. A lex-range query proceeds by computing
$$
\alpha_1=\mathrm{RangeBeg}_T(P_1), \qquad \alpha_2=\mathrm{RangeBeg}_T(P_2).
$$
If $\alpha_1 \ge \alpha_2$, the output is empty. In the simple case emphasized in the description, the patterns share a short $\ell$-prefix, handled by taking a common prefix $X$ up to $\ell = 3\tau-1$ or truncated patterns, with the remaining cases handled by a nonperiodic/periodic split. Let
$$
r=\alpha_2-\alpha_1.
$$
Instead of enumerating suffix-array entries directly, one performs $r$ prefix-select queries of the form $\mathrm{prefix\mbox{-}select}(\mathrm{reverse}(X)\$,i)$ and returns the corresponding outputs [2510.19815].

The reported complexity is that this answers all $r$ elements of the lex-range in
$$
O(r\cdot Q_{\mathrm{sel}} + O(\log\log n)).
$$
More broadly, any data structure using $S(n)$ bits, query time $Q(n)$, build time $P_t(n)$, and working space $P_s(n)$ for suffix-array or lex-range queries on a text of length $n$ can be transformed in $O(P_t)+o(n)$ time into a structure that answers prefix-select queries on $m\approx n/\log n$ short strings in
$$
O(Q(n)+O(\log\log n))
$$
time and
$$
O(S(n)+o(n))
$$
space, and vice versa.

This equivalence is stronger than a single reduction. It states that suffix-array queries are, up to an additive $O(\log\log n)$ term in query time, equivalent to prefix-select queries in all parameters. The framework also proves analogous equivalences for inverse suffix-array queries, pattern ranking, lexicographic range, and $SA$-interval queries, thereby identifying six core problem pairs connecting string and prefix-query models.

## 4. Dyadic decomposition as range-to-prefix conversion

In bloomRF, the range-to-prefix conversion is the standard greedy-from-the-left algorithm for covering an interval $[\ell,r]$ by the minimum number of dyadic intervals. Starting with $x=\ell$, each iteration computes
$$
\mathrm{tz}(x)=\max\{\, k : 2^k \mid x \,\},
\qquad
\lfloor \log_2(r-x+1)\rfloor = \max\{\, k : 2^k \le r-x+1 \,\},
$$
and sets
$$
\mathrm{step}=\min(\mathrm{tz}(x), \lfloor \log_2(r-x+1)\rfloor).
$$
The chosen dyadic block has size $2^{\mathrm{step}}$, its corresponding prefix length is $d-\mathrm{step}$ bits, and the prefix value is the top $d-\mathrm{step}$ bits of $x$, namely $x \gg \mathrm{step}$. The algorithm appends this prefix and advances $x$ by the interval size [2207.04789].

The decomposition size satisfies two bounds. The loop executes at most
$$
m \le 2\lceil \log_2(2^d)\rceil = 2d
$$
steps in the worst case. If the interval length is at most $R$, then
$$
m = O(\log_2 R).
$$
The cover is exact, and the algorithm produces the minimum number of dyadic intervals covering $[\ell,r]$.

In bloomRF these prefixes are consumed by piecewise-monotone hash-functions. A dyadic interval of size $2^\Delta$ corresponds exactly to one word in the bit-array. If a prefix has length $p=d-\mathrm{step}$, then it lives at level $\ell=\mathrm{step}$, which is mapped to layer $i=\ell/\Delta$. Because of the final term
$$
+\, (x \gg \ell_i)\,\&\,(2^\Delta-1),
$$
the least significant $\Delta-1$ bits of the prefix are mapped in order, so that any contiguous set of up to $2^{\Delta-1}$ items inside a dyadic block sits in adjacent bits in a single word. This is the piecewise-monotone property.

The resulting range-to-prefix conversion runs in $O(\#\mathrm{prefixes})=O(\log R)\le O(d)$, and a range query performs one word lookup per prefix. The formal analysis further shows that, because the structure probes at most two words per layer, a range lookup takes $O(k)=O((1/\Delta)\cdot d)$ time, independent of $R$.

## 5. External-memory dual: prefix-to-range conversion

A closely related dual reduction appears in external-memory colored reporting. The colored range reporting problem is defined on sets
$$
C_1,C_2,\ldots,C_m \subseteq \{1,2,\ldots,\sigma\},
$$
with total size $n=\sum_{i=1}^m |C_i|$, and asks for
$$
\bigcup_{i=a}^b C_i
$$
on input $(a,b)$. The colored prefix reporting problem is defined on a static collection
$$
S=\{x_1,x_2,\ldots,x_m\}
$$
of strings, each of length $O(B)$, with a function
$$
c:S\to 2^{\{1,2,\ldots,\sigma\}},
$$
and on input pattern $p$ asks for
$$
\bigcup_{\substack{x\in S\\ x\text{ has prefix }p}} c(x).
$$
The reduction sorts $S$ lexicographically, assigns each string its rank, and sets
$$
C_i = c(x_{(i)}).
$$
All strings having prefix $p$ occupy a contiguous lexicographic interval $[a,b]$, so colored-prefix reporting becomes colored-range reporting on that interval [1104.3084].

The interval computation is performed by a compacted trie, or Patricia trie, storing rank-range pointers at internal nodes. The theorem cited from Belazzougui et al. gives a linear-space structure that, for any pattern $p$ of length $\le O(B)$, returns $(a,b)$ in $O(1)$ I/Os. The colored-range side is answered by a linear-space structure with query cost
$$
O(1+k/B)
$$
I/Os, where $k$ is the output size. Combining the two stages yields colored prefix reporting in
$$
O(1+k/B)
$$
I/Os and $O(n)$ words of space when $m\le n$.

The model assumptions are explicit: the standard Aggarwal–Vitter I/O model with block size $B$ words and unlimited disk, strings of length $O(B)$ so that each occupies $O(1)$ blocks, no indivisibility assumption, and static data with no insertions or deletions.

## 6. Relation to suffix-array functionality and prior reductions

The range-to-prefix viewpoint reorganizes several previously separate reductions into a single prefix-query perspective. The FM-index reduction from suffix-array access to rank on the Burrows–Wheeler Transform is identified as the special case $\ell=1$ of prefix-select, namely $W[i]$ equal to the single BWT symbol and $\mathrm{reverse}(X)\$$ appearing only as one character. The compressed suffix array using the $\Psi$-function also reduces to prefix operations on the BWT array. Recent sublinear-build structures, described as using a variant of prefix-rank/select on synchronizing sets, fit the same template once the range-to-prefix conversion is made explicit [2510.19815].

The principal misconception is to treat range-to-prefix conversion as a single algorithmic trick tied to one data structure. The literature instead exhibits a family of reductions with different ambient models: succinct suffix-array functionality on arbitrary-alphabet texts, approximate range filters on integer universes, and external-memory colored reporting. What remains invariant is the reduction principle: encode a range by prefix descriptors that preserve the order needed by the target structure.

A plausible implication is that prefix queries serve as a canonical intermediate representation for several string and range-reporting tasks. The 2025 equivalence result makes that interpretation explicit by showing that essentially all efficient suffix-array representations can be expressed via prefix-select structures, while the 2011 external-memory result and the 2022 bloomRF construction show that analogous prefix encodings also govern optimal I/O-efficient reporting and compact approximate range filters.

Source: https://www.emergentmind.com/topics/range-to-prefix-conversion-algorithm