0
$\begingroup$

i have this problem. Maybe you guys can help me:

Let's say i have a long sequence of integers, natural numbers, in a random order, but which repeat itself every X numbers (eg: 7 4 9 6 3 7 4 9 6 3 7...). The numbers never repeat within the sequence, so whenever you get the same value twice, you know the sequence has already repeated itself at least once

If i don't know X, but i know it is smaller than a certain number and i can get the value of any position i want, which would be the best strategy, the most efficient, to discover X?

Matt form Argentina :)

Edit: The only things i can think of right now are:

Getting the lcm of half of every possible length to see if that number matches S_1, and then proceed by discard. But this lcm would get way too big way too fast.

Another idea would be checking 2big_number to maybe be able to discard all powers of 2, then powers of 3 and so on, but this leaves many gaps.

Any ideas?

1 Answers 1

0

Let $x = (x_1,x_2\ldots,x_n)$, be a sequence of naturals numbers $x_i$. Then comparing $x_1$ to all the other numbers, followed by comparing $x_2$ to all the numbers, etc., gives an algorithm of running time $$T(n) = \sum_{i=1}^n i = \frac{1}{2}n(n+1) \in O(n^2).$$ I am not sure whether it is the most sufficient algorithm though.

  • 0
    Actually, if you start checking from the first position, you can check each following numebr till you get the same value as the first position. Which means that O = X, worst case O = length of the stream. But is there a better way?2017-01-14