简体   繁体   English

在Union-Find算法中,是否/如何调整路径压缩中节点的等级

[英]In a Union-Find algorithm, whether/how to adjust the rank of a node in path compression

Path compression involves assigning the root as the new parent of every node on the path - this may reduce the rank of the root, and possibly the rank of all nodes on the path. 路径压缩涉及将根分配为路径上每个节点的新父节点 - 这可能会降低根的等级,并可能降低路径上所有节点的等级。 Is there a way to deal with this? 有办法解决这个问题吗? And is it necessary to deal with this? 是否有必要处理这个问题? Or perhaps is it okay to think of rank as the upper bound of the height of the tree instead of the exact height? 或者也许可以将等级视为树高而不是确切高度的上限?

Thanks! 谢谢!

Yes, you can think of the rank as being an upper bound on the height. 是的,您可以将等级视为高度的上限。 Its purpose is to limit the lengths of paths to at most logarithmic, by enforcing the invariant that a tree with less than 2^k nodes has height less than k. 其目的是通过强制具有小于2 ^ k个节点的树的高度小于k的不变量来将路径的长度限制为最多对数。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM