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

后端 未结 2 1490
轮回少年
轮回少年 2021-02-05 09:24

Here\'s a breakdown on the union/find algorithm for disjoint set forests on wikipedia:

  • Barebone disjoint-set forests... (O(n))
    • ... with unio
相关标签:
2条回答
  • 2021-02-05 10:11

    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)

    0 讨论(0)
  • 2021-02-05 10:11

    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.

    0 讨论(0)
提交回复
热议问题