Re: Searching algorithm

• To: mathgroup at smc.vnet.net
• Subject: [mg48351] Re: [mg48253] Searching algorithm
• From: Omega Consulting <info at omegaconsultinggroup.com>
• Date: Tue, 25 May 2004 07:17:20 -0400 (EDT)
• References: <200405190642.CAA12941@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```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