2

My understanding is that tortoise-hare like algorithms works on iterated sequences That is, for any x, succ(x) = x0.

I would like to implement an algortihm that can detect cycles in both deterministic and non-deterministic infinite repeating sequences.

The sequences may have a non-repeating prefix subsequence, for example in the sequence 1666666..., has the prefix of 1 and the repeating pattern 6.

This algorithm would return the longest repeating pattern in a sequence. The repeating pattern of 001100110011... would be 0011, the repeating pattern of 22583575837583758... would be 58357.

My idea was to generate a guess of the longest possible pattern length somehow go from there, but I can't get things in order.

lsund
  • 744
  • 5
  • 16
  • What are you trying to do exactly? you're not very clear – shapiro yaacov Sep 07 '15 at 19:22
  • Sorry if I was not clear enough, I edited the question – lsund Sep 07 '15 at 20:24
  • Are you looking for the most repeated consecutive substring or the longest? Or a mix of both? Also, should the sequence always start at zero or can it be in between? – Thomas Jungblut Sep 07 '15 at 20:37
  • @ThomasJungblut The sequences have a non-repeating prefix (possibly empty sequence) followed by a repeating sequence. The sequence always starts at 0. I edited the question – lsund Sep 07 '15 at 21:07

1 Answers1

1

The tortoise-hare algorithm uses same address to identify cycles. This problem requires a different sort of algorithm. Some form of trie or structure such as LZW compression, would be where I would look for a solution.

mksteve
  • 12,614
  • 3
  • 28
  • 50