MAKE-SET(x)creates a new set whose only member (and thus representative) is x.Since the sets are disjoint,we require that x not already be in some other set. UNION(x,y)unites the dynamic sets that contain x and y,say Sx and S,into a new set that is the union of these two sets.We assume that the two sets are dis- joint prior to the operation.The representative of the resulting set is any member of SxUSy,although many implementations of UNION specifically choose the representative of either Sx or S as the new representative.Since we require the sets in the collection to be disjoint,conceptually we destroy sets Sx and Sy, removing them from the collection 8.In practice,we often absorb the elements of one of the sets into the other set. FIND-SET(x)returns a pointer to the representative of the (unique)set contain- ing x
CONNECTED-COMPONENTS(G) 1 for each vertex v∈G.V b 2 MAKE-SET(V) 3 for each edge (u,v)EG.E 4 if FIND-SET()FIND-SET(v) 5 UNION(u,V) SAME-COMPONENT(,V) 1 if FIND-SET()==FIND-SET(v) 2 return TRUE 3 else return FALSE Edge processed Collection of disjoint sets initial sets {a} {b} {c} d) {e} 份 {g} (h) (i } (b.d0 La) (b.d} {c} Le) 仍 {8} (h) i (e,g) {a} {b,d) {c} {e,g} (h; Ad } (a,c) {a,c} {b.dy {e,g} 份 {h) 》 (h,i0 {a,c} {b,d0 {e,g} {h,} } (a,b) a.b.c,dy {e,g} 份 (h.i } (e,f) a.bc.dy {e,f8} h,i 仍 (b,c) a.bc.dy {e,f8} (h.i }