简体   繁体   English

使用路径压缩查找集而无需按等级合并

[英]Find set with path compression without union by rank

If I have n single node trees and m find set operations (note: no unions, assuming unions have been done before) and use path compression only, is it true that this takes O(m) time? 如果我有n个单节点树并且有m个查找集操作(请注意:假设之前已进行过合并,则没有合并)并且仅使用路径压缩,这是否需要O(m)时间? I've been trying to prove this but it doesn't seem that it is the case. 我一直在试图证明这一点,但事实并非如此。 Since the unions didn't use union by rank a find set can take up to O(n) time. 由于联合不按等级使用联合,因此查找集最多需要O(n)时间。 But is it still possible for m find sets to be done in O(m) time? 但是,仍然有可能在O(m)时间内完成m个查找集?

This in general will not take time O(m) to complete. 通常,这不需要花费时间O(m)即可完成。 Imagine that the n nodes have been split into √n groups and within each group all the nodes are linked together into a linked list of size √n. 想象一下,将n个节点分为√n个组,并且在每个组中,所有节点都链接在一起,成为大小为√n的链表。 Now, if you do √n find operations, one per root of the linked list, the total work done will be Θ(n), because you have to update the pointers on pretty much every node in the group. 现在,如果执行√n次查找操作,则链表的每个根都需要执行一次操作,则总工作量为Θ(n),因为您必须更新组中几乎每个节点上的指针。

However, if you were to do the find operations in a different order (say, by starting at the ends of the linked lists and working backwards), you could do n total operations in O(n) time. 但是,如果要以不同的顺序执行查找操作(例如,通过从链表的末尾开始并向后工作),则可以在O(n)时间内执行n次总操作。

Generally speaking, the cost of union-find using only path compressions is O(m log n + n) for m operations on n nodes . 一般而言, 对于n个节点上的m次操作,仅使用路径压缩进行联合查找的成本为O(m log n + n)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 联合使用路径压缩算法找到不相交集加权快速联合 - union find disjoint set weighted quick union with path compression algorithm 在Union-Find算法中,是否/如何调整路径压缩中节点的等级 - In a Union-Find algorithm, whether/how to adjust the rank of a node in path compression 对于不相交的森林,路径压缩就足够了,为什么我们需要按等级联合 - path compression is enough for disjoint-set forests , why do we need union by rank 路径压缩和按秩联合如何相互补充? - How do path compression and union by rank complement each other? 联合/查找算法没有联合排序为不相交的森林数据结构 - Union/find algorithm without union by rank for disjoint-set forests data structure Union-Find 路径压缩效率 - Union-Find path compression efficiency 联合发现不相交+路径压缩算法 - Union-Find Disjoint+ Path Compression Algorithm 有没有一个例子可以通过在Omega(q log n)中运行的秩来使Union和find算法没有联合? - Is there an example to make Union & find algorithm without union by rank run in Omega(q log n)? 为什么我们不更新路径压缩后不相交集的排名? - Why don't we update rank for disjoint set after path compression? 将路径压缩应用于联合查找总是会导致一棵扁平的树,如果是这样,为什么? - Will applying Path compression to Union Find always results in a flat tree, If so, Why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM