Exercise 4.4.15* (Some combinatorics)

Let f ( n ) denote the number of sequences a 1 , a 2 , , a n that can be constructed where each a j is + 1 , 1 , or 0 , subject to the restrictions that no consecutive terms can be + 1 , and no consecutive terms can be 1 . Prove that f ( n ) is the integer nearest to 1 2 ( 1 + 2 ) n + 1 .

Answers

Proof. Consider the set A n of sequences ( a 1 , a 2 , , a n ) { 0 , 1 , 1 } n satisfying the restrictions that no consecutive terms can be + 1 , and no consecutive terms can be 1 . We define

U n = { ( a 1 , a 2 , , a n ) A n a n = 0 } , V n = { ( a 1 , a 2 , , a n ) A n a n = 1 } , W n = { ( a 1 , a 2 , , a n ) A n a n = 1 } ,

and u n = | U n | , v n = | V n | , w n = | W n | the cardinalities of U n , V n , W n .

Since A n is the disjoint union of U n , V n , W n ,

f ( n ) = u n + v n + w n . (1)

Moreover, for n 2 , if we fix a n = 0 , then any sequence can precede 0 , so u n = u n 1 + v n 1 + w n 1 . If we fix a n = 1 , only the sequences such that a n 1 = 0 or 1 are possible so that v n = u n 1 + w n 1 , and similarly w n = u n 1 + v n 1 . For n 2 , this gives the system

{ u n = u n 1 + v n 1 + w n 1 v n = u n 1 + w n 1 w n = u n 1 + v n 1 { u 1 = 1 v 1 = 1 w 1 = 1 . (2)

Note that v 1 = w 1 and by (1), if v n 1 = w n 1 , then v n = w n , so

n 1 , v n = w n .

By eliminating w n we obtain for n 2 the shortest system

{ u n = u n 1 + 2 v n 1 v n = u n 1 + v n 1 { u 1 = 1 v 1 = 1 . (3)

We give to u 0 and u 1 the conventional values u 0 = 1 , v 0 = 0 , so that for all n 1 ,

{ u n = u n 1 + 2 v n 1 v n = u n 1 + v n 1 { u 0 = 1 v 0 = 0 . (4)

We may write (4) in the form

( u n v n ) = ( 1 2 1 1 ) ( u n 1 v n 1 ) ( n 1 ) . (5)

We define A = ( 1 2 1 1 ) , and M n = ( u n v n ) , so that M n + 1 = A M n for every n . Then

M n = A n M 0 .

The eigenvalues of A are the roots of

P A ( x ) = det ( A λI ) = | 1 x 2 1 1 x | = ( x 1 ) 2 2 = ( x 1 + 2 ) ( x 1 2 ) = ( x λ ) ( x μ ) ,

where

λ = 1 + 2 , μ = 1 2 .

The eigenvalues are distinct, so there is a matrix P such that P 1 AP = ( λ 0 0 μ ) . Therefore

A n = P ( λ n 0 0 μ n ) P 1 ,

so

( u n v n ) = P ( λ n 0 0 μ n ) P 1 ( u 0 v 0 ) = ( c λ n + d μ n e λ n + f μ n ) ,

where c , d , e , f are constant real numbers. Then

f ( n ) = u n + 2 v n = a λ n + b μ n , (6)

where a = c + 2 e , b = d + 2 f .

(Alternatively, we can prove (6) without linear algebra by showing with (4) that u n + 1 = 2 u n + u n 1 , v n + 1 = 2 v n + v n 1 and f ( n + 1 ) = 2 f ( n ) + f ( n 1 ) for n 1 , and using Theorem 4.10.)

We find a and b with the values f ( 0 ) = u 0 + 2 v 0 = 1 and f ( 1 ) = u 1 + v 1 = 3 . Then

{ a + b = 3 , + = 7 ,

so

a = 3 μ λ μ = 2 + 2 2 2 = 1 2 ( 1 + 2 ) = λ 2 , b = λ 3 λ μ = 2 + 2 2 2 = 1 2 ( 1 2 ) = μ 2 .

Therefore

f ( n ) = 1 2 ( λ n + 1 + μ n + 1 = 1 2 [ ( 1 + 2 ) n + 1 + ( 1 2 ) n + 1 ] .

Moreover, 1 2 < 2 < 0 , so | 1 2 | < 1 2 , therefore

1 2 | 1 2 | n + 1 < 1 2 n + 2 < 1 2 ,

thus

| f ( n ) 1 2 [ ( 1 + 2 ) n + 1 ] | < 1 2 .

Therefore f ( n ) is the integer nearest to 1 2 ( 1 + 2 ) n + 1 . We can write

f ( n ) = 1 2 ( 1 + 2 ) n + 1 + 1 2 .

Note: We give some ways to compute f ( n ) with Sagemath.

def f(n):
    u, v = 1, 1
    for i in range(1, n):
        u, v = u + 2 * v, u + v
    return u + 2 * v

def f(n):
    a = (1/2) * (1 + sqrt(2))^(n + 1) + (1/2) * (1 - sqrt(2))^(n + 1)
    return int(round(a.n(), 2))

def f(n):
    a = (1/2) * (1 + sqrt(2))^(n + 1)
    return floor(a.n() + 0.5)

 def f(n):
     A =  matrix([[1,2], [1,1]])
     B = A^n
     return B[0][0]  + 2 * B[1][0]

  [f(n) for n in range(1, 10)]
           [3, 7, 17, 41, 99, 239, 577, 1393, 3363]

(same results for the four solutions).

The best is the last solution, which computes only with integers, and uses fast exponentiation of matrices, so T ( n ) = O ( log ( n ) ) .

User profile picture
2025-02-23 11:35
Comments