RMQ
点击放大图片
注意LCAT(u, v)是在对T进行dfs过程当中在访问u和v之间离根结点最近的点。因此我们可以考虑树的欧拉环游过程u和v之间所有的结点,并找到它们之间处于最低层的结点。为了达到这个目的,我们可以建立三个数组:
E[1, 2*N-1] - 对T进行欧拉环游过程中所有访问到的结点;E[i]是在环游过程中第i个访问的结点
L[1,2*N-1] - 欧拉环游中访问到的结点所处的层数;L[i]是E[i]所在的层数
H[1, N] - H[i] 是E中结点i第一次出现的下标(任何出现i的地方都行,当然选第一个不会错)
假定H[u]<H[v](否则你要交换u和v)。可以很容易的看到u和v第一次出现的结点是E[H[u]..H[v]]。现
在,我们需要找到这些结点中的最低层。为了达到这个目的,我们可以使用RMQ。因此 LCAT(u, v) = E[RMQL(H[u], H[v])] (记住RMQ返回的是索引),下面是E,L,H数组:

点击放大图片
Range Minimum Query and Lowest Common Ancestor By danielp TopCoder Member Introduction Notations Range Minimum Query (RMQ) Trivial algorithms for RMQ A <O...
Topcoder 上有一篇详细阐述 RMQ 问题的“ Range Minimum Query and Lowest Common Ancestor ”,网上也有翻译版。在此,我来简单引用 & 总结下。至于为何要总结 ...
The lowest common ancestor is defined between two nodes v and w as the ... Range Minimum Query an... 23页 1下载券 Range Minimum Query an... ...
RMQ:Range Minimum Maximum Query – 在一个序列上,给定区间,求区间极值 ? LCA:Lowest Common Ancestor – 最近公共祖先是一个节点,是指定两点的祖先, 且深度...
(smallest lowest common ancestor) problem, and ...Query instances of XQuery FT and XML IR/fragment...Structural join of XML based on range partitioning...
(smallest lowest common ancestor); dewey encoding;...Query instances of XQuery FT and XML IR/fragment...Structural join of XML based on range partitioning...
lca = lowest common ancestor ? u = lca(v,w): v と w の共通の祖先 ...5 6 7 8 9 10 11 u v mw 5 6 13 Range Minimum Query 问题 (RMQ) ...
Abstract. The Range-Minimum-Query-Problem is to preprocess an array such ...1 Introduction The problem of ?nding the lowest common ancestor (LCA) of ...
Key words:algorithm design; binary tree; inorder traversal; query fast 摘要...[18] Daniel P.Range minimum query and lowest common ancestor[EB/OL]. ...
// 与根结点U合并(并查集操作) Find(u).ancestor?:=?u?? // 将u所在...57、P94? ②《Range? Minimum? Query? and? Lowest? Common? Ancestor》by?...
热门文档