MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Faster ways to unionize intersecting sets?


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?