Your skill will accomplish what the force of many cannot |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Imagine the repeat sequence we are trying to detect is:
So the input stream will look something like:
but we may start sampling at any point. eg.
If we maintain rolling checksums, then:
But this would require us to store checksums covering every start-point and every end-point, for 2 full-but-disjoint repeats. That's N^2 checksums, which is more expensive than storing the data. Unless there is some way to determine that we can discard those checksums that cannot be the one we want. Ie. If when we read the 3rd value, and calculate the 2-value checksum for that value and its immediate predecessor and it doesn't match the checksum for the first two values, we know that our sequence must be longer than 2, and can discard both 2-value checksums. Ditto, when we read the fourth value, and calculate the checksum for the last 3 values and it does not match that of the first 3, we can discard both. But, when we calculated the 3-value checksum having read the fourth value, we needed the 2-value checksums; and when we come to calculate the 4-value checksums having read the 5 value, we need the 3-value checksums; So the discarding of earlier checksums has to be deferred by one iteration cycle. In reply to Re: Algorithm inspiration required. (Further thoughts on rolling checksums)
by BrowserUk
|
|