Professional Documents
Culture Documents
Data Structure For Disjoint Sets
Data Structure For Disjoint Sets
Data Structure For Disjoint Sets
4 connected components
21-3
{f, g, d}
make-set(x)
head x
/
worst-case: O(n), best-case: O(1) amortized
* O(n2) time for m=2n-1 operations. ** m =n+u
u = n -1
* An example showing (n ) for O(n) operations.
2
n Make
O(n)
1+1
1+2 n-1 Union
1+3 O(k)
1 + (n - 1) O(n2)
(1)
*rank = 100
e
d
c
b
a
x rank = 0
root
union by rank 大
小
21-8
set x’s parent as the root
the root
the root
21-8x
2j
g(j)
17-13a