开发者

in a series of n elements of arithmetic progression, [n/2] elements are changed. Find the difference in the initial arithmetic progression

I have a list of size n which contains n consecutive members of an arithmetic progression which are not in order. I changed less than half of the elements in this list with some random integer. From this new list, how can I find the difference of the initial arithmetic progression?

I thought开发者_Python百科 a lot about it but except brute force, I was not able to come up with any other thing :(

Thanks for thinking on this one :)


It's not possible to solve this in general and be 100% sure that your answer is correct. Let's say that the initial list is the following arithmetic progression (not in order):

1 3 2 4

Change less than half the elements at random... let's say for example that we changed 2 to 5:

1 3 5 4

If we can first find out which numbers we need to change to obtain a valid shuffled arithmetic sequence then we can easily solve the problem stated in the question. However we can see that there are multiple possible answers depending in which we number we choose to change:

  • 6, 3, 5, 4 (difference is 1)
  • 1, 3, 2, 4 (difference is 1)
  • 1, 3, 5, 7 (difference is 2)

There is no way to know which of these possible sequence is the original sequence, so you cannot be sure what the original difference was.


Since there is no deterministic solution for the problem (as stated by @Mark Byers), you can try a probabilistic approach.

It's difficult to obtain the original progression, but its rate can be obtained easily by comparing the differences between elements. The difference of original ones will be multiples of rate.

Consider you take 2 elements from the list (probability that both of them belongs to the original sequence is 1/4), and compute the difference. This difference, with probability of 1/4, will be a multiple of the rate. Decompose it to prime factors and count them (for example, 12 = 2^^2 * 3 will add 2 to 2's counter and will increment 3's counter).

After many such iterations (it looks like a good problem for probabilistic methods, like Monte Carlo), you could analize the counters.

If a prime factor belongs to the rate, its counter will be at least num_iteartions/4 ( or num_iterations/2 if it appears twice).

The main problem is that small factors will have large probability on random input (for example, the difference between two random numbers will have 50% probability to be divisible by 2). So you'll have to compensate it: since 3/4 of your differences were random, you'll have to consider that (3/8)*num_iterations of 2's counter must be ignored. Since this also applies to all powers of two, the simpliest way is to pregenerate "white noise mask" by taking the differences only between random numbers.

EDIT: let's take this approach further. Consider that you create this "white noise mask" (let's call it spectrum) for random numbers, and consider that it's base-1 spectrum, since their smallest "largest common factor" is 1. By computing it for a differences of the arithmetic sequence, you'll obtain a base-R spectrum, where R is the rate, and it will equivalent to a shifted version of base-1 spectrum. So you have to find the value of R such that

your_spectrum ~= spectrum(1)*3/4 + spectrum(R)*1/4

You could also check for largest number R such that at least half of the elements will be equal modulo R.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜