arXiv:2610.38327cs.DSOct 2026

Manuscript Offprint

arXiv:2610.38327

Optimal Encodings for Next/Previous Larger/Smaller Value Queries: A Unified Approach

Seungbum Jo, Geunho Kim, Kunihiko Sadakane, Srinivasa Rao Satti

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Given a 1D array over a total order and a query position in the array, a next larger value query returns the nearest position to the right whose value is larger than the value at the query position. Next smaller value queries and previous larger/smaller value queries are defined analogously. These queries are closely related to the k-th range minimum/maximum problem, which asks for the position of the k-th leftmost minimum/maximum value when the query range contains multiple minimum/maximum values.

In this paper, we consider the encoding problem for answering any arbitrary subfamily of these four queries, where the queries must be answered without accessing the input array. We give a unified approach for obtaining space lower bounds for such encodings. We also obtain data structures for the query subfamilies that match the lower bounds up to lower-order additive terms, while supporting the queries in constant time. Our results generalize and improve several previous results on this problem [Gawrychowski and Nicholson, ICALP-2015; Jo and Satti, TCS-2016; Tsur, IPL-2019; Jo and Kim, Algorithmica-2025].

In addition, these results give tight bounds on the encoding complexity of all subfamilies of these queries for (1) permutations, (2) arrays without consecutive equal elements, and (3) general arrays.

2012 ACM Subject Classification Theory of computation → Data structures design and analysis

Keywords and phrases Encoding data structures, Colored 2d min/max heaps, Generating trees, Quarter-plane walks

1 Introduction

Given an array A[1,…,n]A[1,\ldots,n] over a total order, and a query position ii, we consider the following queries:

  1. PSV(i)PSV(i), the previous smaller value query, returns max⁡{j<i:A[j]<A[i]}\max\{j<i:A[j]<A[i]\}, or 0 if no such position exists.

  2. PLV(i)PLV(i), the previous larger value query, returns max⁡{j<i:A[j]>A[i]}\max\{j<i:A[j]>A[i]\}, or 0 if no such position exists.

  3. NSV(i)NSV(i), the next smaller value query, returns min⁡{j>i:A[j]<A[i]}\min\{j>i:A[j]<A[i]\}, or n+1n+1 if no such position exists.

  4. NLV(i)NLV(i), the next larger value query, returns min⁡{j>i:A[j]>A[i]}\min\{j>i:A[j]>A[i]\}, or n+1n+1 if no such position exists.

We also consider the following range queries. Given an interval [i,j][i,j] and a positive integer kk, let p1<p2<⋯<ptp_1<p_2<\cdots<p_t be the positions of the minimum element in A[i,…,j]A[i,\ldots,j], and let q1<q2<⋯<qsq_1<q_2<\cdots<q_s be the positions of the maximum element in A[i,…,j]A[i,\ldots,j].

  1. The kk-th range minimum query, denoted by RMin(i,j,k)\text{RMin}(i,j,k), returns pkp_k if k≤tk\leq t, and ptp_t otherwise.

  2. The kk-th range maximum query, denoted by RMax(i,j,k)\text{RMax}(i,j,k), returns qkq_k if k≤sk\leq s, and qsq_s otherwise.

We consider the above queries on the following classes of arrays:

  1. P=⋃n≥1Pn\mathcal{P}=\bigcup_{n\geq 1}\mathcal{P}_n, where Pn\mathcal{P}_n denotes the set of all permutations of length nn.

  2. A′=⋃n≥1An′\mathcal{A}'=\bigcup_{n\geq 1}\mathcal{A}'_n, where An′\mathcal{A}'_n denotes the set of all arrays A[1,…,n]A[1,\ldots,n] such that A[i−1]≠A[i]A[i-1]\neq A[i] for every 1<i≤n1<i\leq n.

  3. A=⋃n≥1An\mathcal{A}=\bigcup_{n\geq 1}\mathcal{A}_n, where An\mathcal{A}_n denotes the set of all arrays of length nn.

These queries are widely studied primitives for accessing the order structure of an array. Previous/next smaller value queries are used to support navigational queries on compressed suffix trees [22]. They also arise in the all-nearest-smaller-values problem, which has been studied in the context of parallel algorithms [1]. Also, as a special case of kk-th range minimum queries, the problem to find the median among them (range minima in the middle queries) was considered by Fischer and Heun [10] for efficient construction of compressed suffix arrays.

We study the problem of designing data structures for each subfamily of {PSV,PLV,NSV,NLV}\{\text{PSV}, \text{PLV}, \text{NSV}, \text{NLV}\} on each of the three array classes. We work in the encoding model [23]: after preprocessing, the input array is discarded, and all queries must be answered using only the stored representation. In this model, if a query family distinguishes NN equivalence classes of input objects, then any representation requires at least ⌈log⁡N⌉\lceil \log N \rceil bits1^1; we call this the information-theoretic lower bound (ITLB). Here, two objects are equivalent if the queries in the family give identical answers on them. A representation matching the ITLB up to lower-order terms is called succinct. In many cases, the ITLB is much smaller than the space needed to store the input array itself [23]. Throughout the paper, we assume the word-RAM model with word size w=Θ(log⁡n)w=\Theta(\log n).

We also consider range queries because of their close connections to the previous/next smaller/larger value queries. From a lower bound perspective, {PSV,NSV}\{\text{PSV}, \text{NSV}\} and {RMin}\{\text{RMin}\} induce the same equivalence classes of arrays, as do {PLV,NLV}\{\text{PLV}, \text{NLV}\} and {RMax}\{\text{RMax}\}, and hence have

1^1 All logarithms are base two. Throughout the paper, we omit ceilings and floors when they affect the bounds only by an additive constant.

Optimal Encodings for Next/Previous Larger/Smaller Value Queries: A Unified Approach

the same ITLBs (see Proposition 5). For upper bounds, colored 2d-min heaps [9] provide a structure for supporting PSV, NSV, and RMin simultaneously; colored 2d-max heaps similarly support PLV, NLV, and RMax (see Section 2 for definitions).

References (65)