赞
踩
选项 | |
---|---|
A | 1 and -6 |
B | 4 and -5 |
C | 8 and -5 |
D | 8 and -6 |
选项 | |
---|---|
A | { 4, 6, 5, 2, 6, -7, 3 } |
B | { 4, 6, 5, 2, -7, 5, 3 } |
C | { 6, 6, 5, 6, -7, 5, 5 } |
D | { 6, 6, 5, 6, 6, -7, 5 } |
选项 | |
---|---|
A | a. elements of index 2 and 5 |
B | a. elements of index 2 and 6 |
C | a. elements of index 4 and 5 |
D | a. elements of index 4 and 6 |
选项 | |
---|---|
A | at leatst m |
B | exactly n |
C | exactly m−n |
D | at least m−n |
选项 | |
---|---|
A | { 4, 6, 5, 2, 6, -7, 3 } |
B | { 4, 6, 5, 2, -7, 5, 3 } |
C | { 6, 6, 5, 6, -7, 5, 5 } |
D | { 6, 6, 5, 6, 6, -7, 5 } |
选项 | |
---|---|
A | O(log2n) |
B | O(n) |
C | O(n2) |
D | O(nlog2n) |
选项 | |
---|---|
A | at leatst m |
B | exactly n |
C | exactly m−n |
D | at least m−n |
union( find(4), find(6) )
union( find(2), find(7) )
union( find(0), find(4) )
union( find(7), find(6) )
union( find(7), find(1) )
注意:这里假设按规模求并(若两集合规模相等,则把第1个集合的根结点作为结果的根结点),并且用带路径压缩的查找。对所有的0≤i≤7,S[i]被初始化为−1。
i | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
---|---|---|---|---|---|---|---|---|
S[i] | 4 | 4 | 4 | -1 | -6 | -1 | 4 | 2 |
SetType Find ( ElementType X, DisjSet S )
{
ElementType root, trail, lead;
for ( root = X; S[root] > 0; root = S[root]) ;
for ( trail = X; trail != root; trail = lead ) {
lead = S[trail] ;
S[trail] = root;
}
return root;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。