Content deleted Content added
m →Disjoint-set forests: reword a bit |
m average -> amortized (accuracy) |
||
Line 35:
In this naive form, this approach is no better than the linked-list approach, because the tree it creates can be highly unbalanced, but it can be enhanced in two ways.
The first way, called ''union by rank'', is to always attach the smaller tree to the root of the larger tree, rather than vice versa. To evaluate which tree is larger, we use a simple heuristic called ''rank'': one-element trees have a rank of zero, and whenever two trees of the same rank are unioned together, the result has one greater rank. Just applying this technique alone yields an
'''function''' MakeSet(x)
Line 64:
'''return''' root
These two techniques complement each other; applied together, the
In fact, we can't get better than this: Fredman and Saks showed in [[1989]] that Ω(α(n)) words must be accessed by ''any'' disjoint-set data structure per operation on average.
|