Union/find algorithm without union by rank for disjoint-set forests data structure

佐手、 提交于 2019-12-03 06:03:55

I googled for "without union by rank" and the second link that came up was this one:

...We close this section with an analysis of union–find with path compression but without union by rank...

The union-find datastructure with path compression but without union by rank processes m find and n-1 link operations in time O((m+n) log n)

Path compression flattens the tree structure. Union by rank helps to merge. Assume that you skip the latter. So now, you have a forest with no rank information to choose how to merge. Potentially, you now run the risk of merging a tree with a larger depth to one with a smaller depth -- leading to an unbalanced tree structure. In the worst case, you may end up with a linked list. Your Union's amortized time complexity increases even if that for Find remains the same.

IMO, It'd be better to skip path compression but not rank.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!