Let me first ask the question "how many 0-1 sequences of length n exist without two consecutive 1s?" Let the answer be A (n). We have A (0) = 1 (empty sequence), A (1) = 2 ("0" and "1"), A (2) = 3 ("00", "01" and "10", but a not "11").
To simplify the notation of repetition, we calculate A (n) as the sum of two numbers:
B (n), the number of sequences that end with 0, and
C (n), the number of sequences that end with 1.
Then B (n) = A (n-1) (take any such sequence of length n-1 and add 0)
and C (n) = B (n-1) (because if you have 1 in position n, you should have 0 on n-1.)
This gives A (n) = B (n) + C (n) = A (n-1) + B (n-1) = A (n-1) + A (n-2). By now, this should be familiar :-)
A (n) is just the Fibonacci number F n + 2 , where the Fibonacci sequence is defined:
F 0 = 0, F 1 = 1, and F n + 2 = F n + 1 + F n for n? 0.
Now for your question. We will calculate the number of agreements with 1 = 0 and a 1 = 1 separately. For the first, 2 ? a n can be any sequence in general (without consecutive 1s), so the number is A (n-1) = F n + 1 . For the latter, we must have 2 = 0, and then a 3 & hellip; a n is any sequence without consecutive 1s that ends with 0, i.e. B (n-2) = A (n-3) = F n-1 .
So the answer is: F n + 1 + F n-1 .
Actually, we can go even further than this answer. Please note that if you call the answer as
G (n) = F n + 1 + F n-1 , then
G (n + 1) = F n + 2 + F n and
G (n + 2) = F n + 3 + F n + 1 , so even G (n) satisfies the same recurrence as the Fibonacci sequence! [In fact, any linear combination of Fibonacci-related sequences will satisfy the same repetition, so this is not all that is surprising.] Thus, another way of calculating the answers will use:
G (2) = 3
G (3) = 4
G (n) = G (n-1) + G (n-2) for n? 4.
And now you can also use the closed form F n = ([alpha] n - [beta] n ) / ([alpha] - [beta]) (where [alpha] and [beta] are (1 - β5) / 2, the roots x 2 -x-1 = 0) to get
G (n) = ((1 + β5) / 2) n + ((1-β5) / 2) n .
[You can ignore the second term because it is very close to 0 for large n, in fact G (n) is the closest integer to ((1 + β5) / 2) n for all n & ge; 2.] Sub>