Chapter11-DisjointSets(ACM之并查集学习)DataStructureforDisjointSets 11.1Disjoint-set指令 Disjointset資料結構:資料結構:1.一個維護所有disjointdynamicsets組成的大集合S={S1,S2,…,Sk}的資料結構。2.每個集合都被一個representative所代表,而representative是該集合中的某一個元素。DisjointSets 2 3.此資料結構...
disjoint set (use MakeSet) Consider each graph edge in turn: if the two endpoints are in different sets (use FindSet to test), then Union the two sets together End result is that there is one set in the disjoint sets data structure for each connected component of the graph, containing ...
Apossibleforestrepresentationofthesesets (2)Find(i)::=FindthesetSkwhichcontainstheelementi.§3BasicDataStructure Union(i,j)Idea:MakeSiasubtreeofSj,orviceversa.Thatis,wecan settheparentpointerofoneoftherootstotheotherroot.10 484 10 6 7 1 9 S1S2 1 9 10 6 7 8 ...
( i ) ::= Find the set S k which contains the element i. 3/12 §3 Basic Data Structure Union ( i, j ) Idea: Make S i a subtree of S j , or vice versa. That is, we can set the parent pointer of one of the roots to the other root. 10 6 8 7 4 1 9 4 1 9 10 ...
Algorithmtofindallconnectedcomponentsinanundirectedgraph Initiallymakeeachgraphvertexintoitsowndisjointset(useMakeSet) Considereachgraphedgeinturn: ifthetwoendpointsareindifferentsets(useFindSettotest),thenUnionthetwosetstogether Endresultisthatthereisonesetinthedisjointsetsdatastructureforeachconnectedcomponentofthe...