正在加载图片...
令 Analysis Uvnneaking, union an/ Pmac Sure. Try this one T=⊙(N2)! union (2, 1), find (1); union (3, 2), find (1; That’snot good. union(N,N-1), find(1). e cl 3 5·)J,4 Algorithm usin INitialize for (k= 1 if Find SetUn❖ Analysis Practically speaking, union and find are always paired. Thus we consider the performance of a sequence of union￾find operations. 〖Example〗 Given S = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 } and 9 relations: 124, 31, 610, 89, 74, 68, 35, 211, 1112. We have 3 equivalence classes { 2, 4, 7, 11, 12 }, { 1, 3, 5 }, and { 6, 8, 9, 10 } Algorithm using union-find operations { Initialize Si = { i } for i = 1, ..., 12 ; for ( k = 1; k <= 9; k++ ) { /* for each pair i  j */ if ( Find( i ) != Find( j ) ) SetUnion( Find( i ), Find( j ) ); } } Can you think of a worst case example? Sure. Try this one: union(2, 1), find(1); union(3, 2), find(1); ..., ... ; union(N, N −1), find(1). N N−1  1 T = ( N2 ) ! That’s not good
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有