Let me see if I can explain, limal. There are n sequences, each of length m. A pattern may consist of a match (1) or no-match (0) in each position of the sequence, such as 100101001. Think of it as a match "template". There are 2^m-1 patterns (disregarding the case of all zeros). To find all the matches, use each match template to compare every sequence to every other sequence, for a total of (2^m-1)*sum(1..n-1) comparisons.
Now let's see how many it would take to find all of them using the "naive" algorithm. The algorithm used by GrandFather makes only sum(1..n-1) comparisons. But consider a hypothetical set of 6 sequences. At the end of the naive algorithm, sequence 5 might match 6 in some way. However, this match may also occur in earlier sequences. So to find these would require that this specific match be checked against all the other sequences. Therefore, to find all possible matches would require (n-1)*sum(1..n-1) comparisons.
Depending on the sizes of m and n, either method may be faster. For the case at hand (m=9,n=2000), the naive algorithm requires 1999*sum(1..1999)=3,996,001,000 comparisons, while my pattern template algorithm only requires (2^9-1)*sum(1..1999)=1,021,489,000 comparisons. This makes my algorithm faster (meaning fewer comparisons) by a factor of (n-1)/(2^m-1)=3.9119 . As an added bonus, it also finds all of the submatches, although kdt2006 has expressed that they are not needed. | [reply] |
Maybe I just need some coffee, but GrandFathers algorithm generates the list of all maximum patterns including the sequence ids. In your example, the hash would contain something like
$matches{$pattern} = [ [1,3], ... [ 5, 6 ], ];
after sum(1..n-1) comparsions. Isn't that what kdt2006 asked for? | [reply] [d/l] |