MathGroup Archive 2004

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

Search the Archive

Re: Searching algorithm


On May 19, 2004, at 1:42 AM, Amir wrote:

> Hello,
>
> A =  2x2 matrix {{1,8,9,4,6,3},{1,7,9,11,8,54},{73,2,1,61,8,9},...}
>
> Is there any algorithm which can find the most frequent subset of three
> numbers ( like {1,8,9} ) that appears in  A ?
>
> Thanks,
>
> Amir

Here's one method.

In[1]:=
A =  {{1,8,9,4,6,3},{1,7,9,11,8,54},{73,2,1,61,8,9}};

In[2]:=
variations[lst_] :=
  Module[{perm, starts},
   perm=Permutations[lst];
   Union[Map[Sort[Take[#,3]]&, perm]]
   ]

In[3]:=
triples=Flatten[Map[variations,A], 1]

In[4]:=
<<Statistics`

In[5]:=
Sort[Frequencies[triples]][[-1,-1]]
Out[5]=
{1,8,9}

Ofcourse, there could be multiple triples that occur at the same 
maximum frequency. I'm not sure what you want to do in that case.

----------------------------------------------
Omega Consulting
The final answer to your Mathematica needs.
http://omegaconsultinggroup.com


  • Prev by Date: Re: Tree and Lists
  • Next by Date: Re: Eigensystem: different solution in V5.0 and V4.1 ??
  • Previous by thread: Searching algorithm
  • Next by thread: RE: Searching algorithm