We study the following one-dimensional range reporting problem: On an array A of n elements, support queries that given two indices i ≤ j and an integer k report the k smallest elements in the subarray A[i..j] in sorted order. We present a data structure in the RAM model supporting such queries in optimal O(k) time. The structure uses O(n) words of space and can be constructed in O(n logn) time. The data structure can be extended to solve the online version of the problem, where the elements in A[i..j] are reported one-by-one in sorted order, in O(1) worst-case time per element. The problem is motivated by (and is a generalization of) a problem with applications in search engines: On a tree where leaves have associated rank values, report the highest ranked leaves in a given subtree. Finally, the problem studied generalizes the classic range minimum query (RMQ) problem on arrays.
[1]
Robert E. Tarjan,et al.
Fast Algorithms for Finding Nearest Common Ancestors
,
1984,
SIAM J. Comput..
[2]
Jean Vuillemin,et al.
A unifying look at data structures
,
1980,
CACM.
[3]
Michael L. Fredman,et al.
Surpassing the Information Theoretic Bound with Fusion Trees
,
1993,
J. Comput. Syst. Sci..
[4]
Greg N. Frederickson,et al.
An Optimal Algorithm for Selection in a Min-Heap
,
1993,
Inf. Comput..
[5]
Rajeev Motwani,et al.
The PageRank Citation Ranking : Bringing Order to the Web
,
1999,
WWW 1999.
[6]
Donald B. Johnson,et al.
The Complexity of Selection and Ranking in X+Y and Matrices with Sorted Columns
,
1982,
J. Comput. Syst. Sci..