Given an array A[1: n] of n elements drawn from an ordered set, the sorted range selection problem is to build a data structure that can be used to answer the following type of queries efficiently: Given a pair of indices i, j $ (1\le i\le j \le n)$, and a positive integer k, report the k smallest elements from the sub-array A[i: j] in order. Brodal et al. (Brodal, G.S., Fagerberg, R., Greve, M., and L{\'o}pez-Ortiz, A., Online sorted range reporting. Algorithms and Computation (2009) pp. 173--182) introduced the problem and gave an optimal solution. After O(n log n) time for preprocessing, the query time is O(k). The space used is O(n). In this paper, we propose the only other possible optimal trade-off for the problem. We present a linear space solution to the problem that takes O(k log k) time to answer a range selection query. The preprocessing time is O(n). Moreover, the proposed algorithm reports the output elements one by one in non-decreasing order. Our solution is simple and practical.
翻译:给定一个从有序集合中抽取的n个元素构成的数组A[1: n],“排序区间选择问题”的目标是构造一种数据结构,能够高效地回答以下类型的查询:给定一对索引i、j(1≤i≤j≤n)和一个正整数k,按顺序返回子数组A[i: j]中最小的k个元素。Brodal等人(Brodal, G.S., Fagerberg, R., Greve, M., 和López-Ortiz, A., Online sorted range reporting. Algorithms and Computation (2009) 第173–182页)首次提出该问题并给出了一个最优解。在O(n log n)时间预处理后,查询时间为O(k),空间复杂度为O(n)。本文提出了该问题唯一另一种可能的最优权衡方案:我们给出一个线性空间的解法,回答区间选择查询需要O(k log k)时间,预处理时间为O(n)。此外,所提算法按非递减顺序逐一输出结果元素。我们的解法简单且实用。