如何在实践中回答小批量RMQ或LCA查询
How to answer a small batch of RMQs or LCA queries in practice
摘要:
在范围最小查询(RMQ)问题中,我们给出了一个$n$数的数组$A$,并要求我们回答以下类型的查询:对于$0$和$n-1$之间的索引$i$和$j$,查询$\text{RMQ}_A(i,j)$返回子数组$A[i..j]$中最小元素的索引。在许多实际应用中,生成一小批RMQ是一项核心计算任务,特别是由于与最低共同祖先(LCA)问题的联系。对于小批量,我们的意思是查询的数量$q$是$o(n)$,并且我们手头都有。因此,构建$Ω(n)$大小的数据结构或花费$Ω(n)$时间构建更简洁的数据结构是不相关的。众所周知,在从业者和其他地方,这些用于在线查询的数据结构在其预处理和查询时间中具有很高的常数。因此,我们希望在实践中有效地回答这一批问题。在实践中,我们的意思是我们(最终)希望花费$n + \mathcal{O}(q)$时间和$\mathcal{O}(q)$空间。我们编写$n$是为了强调$A$的每个条目的操作数应该是一个非常小的常数。在这里,我们将展示如何现有的算法可以很容易地修改,以满足这些条件。实验结果表明了该方案的实用性。获得的最显着的改进是回答一小批LCA查询。所提出的算法的库实现。
英文摘要:
In the Range Minimum Query (RMQ) problem, we are given an array $A$ of $n$ numbers and we are asked to answer queries of the following type: for indices $i$ and $j$ between $0$ and $n-1$, query $\text{RMQ}_A(i,j)$ returns the index of a minimum element in the subarray $A[i..j]$. Answering a small batch of RMQs is a core computational task in many real-world applications, in particular due to the connection with the Lowest Common Ancestor (LCA) problem. With small batch, we mean that the number $q$ of queries is $o(n)$ and we have them all at hand. It is therefore not relevant to build an $Ω(n)$-sized data structure or spend $Ω(n)$ time to build a more succinct one. It is well-known, among practitioners and elsewhere, that these data structures for online querying carry high constants in their pre-processing and querying time. We would thus like to answer this batch efficiently in practice. With efficiently in practice, we mean that we (ultimately) want to spend $n + \mathcal{O}(q)$ time and $\mathcal{O}(q)$ space. We write $n$ to stress that the number of operations per entry of $A$ should be a very small constant. Here we show how existing algorithms can be easily modified to satisfy these conditions. The presented experimental results highlight the practicality of this new scheme. The most significant improvement obtained is for answering a small batch of LCA queries. A library implementation of the presented algorithms is made available.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。