[英]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.