Re: Faster ways to unionize intersecting sets?

• To: mathgroup at smc.vnet.net
• Subject: [mg70276] Re: Faster ways to unionize intersecting sets?
• From: "Ray Koopman" <koopman at sfu.ca>
• Date: Wed, 11 Oct 2006 01:53:32 -0400 (EDT)
• References: <eg02a3\$81m\$1@smc.vnet.net><eg2e4o\$70u\$1@smc.vnet.net> <eg81ph\$mqh\$1@smc.vnet.net>

I think this gives what you want, but in a different order.

In[1]:= mergeSets3[s_List] := Module[
{c = Outer[Sign@Length@Intersection@##&,s,s,1]},
While[c != (c = Sign[c.c])]; Union @@@ (Pick[s,#,1]& /@ Union @ c) ]

In[2]:= s = {{1,2},{2,3},{4,5},{6,7},{7,5},{9,10},{11,12},{13,14}};

In[3]:= mergeSets3[s]

Out[3]= {{13,14},{11,12},{9,10},{4,5,6,7},{1,2,3}}

lsha wrote:
> Hi,
>
> I tried mergeSets2[] and the answer is different from mergeSets[].
> An example:
> In[34]:=
> s = {{1, 2}, {2, 3}, {4, 5}, {6, 7}, {7, 5}, {9, 10}, {11, 12}, {13, 14}};
>
>
> In[35]:=
> mergeSets[s]
> Out[35]=
> {{1, 2, 3}, {4, 5, 6, 7}, {9, 10}, {11, 12}, {13, 14}}
>
>
> In[36]:=
> mergeSets2[s]
> Out[36]=
> {{{9, 10}, {11, 12}, {13, 14}}, {1, 2, 3, 4, 5, 6, 7}}
>
> The non-intersecting singles are correct but the intersecting sets are all
> merged together with mergeSets2[].
>
> Regards,
> Ling Sha
>

• Prev by Date: Re: Copy input and User Defined Variables
• Next by Date: RE: Copy input and User Defined Variables
• Previous by thread: Re: Re: Faster ways to unionize intersecting sets?
• Next by thread: Re: Faster ways to unionize intersecting sets?