1
$\begingroup$

Let $x\ge 1, x \in \mathbb N$ and let $t(n)$ be the number of sequences of length $n$ such that their elements belong to the set $\{0,1,2,...,2x\}$. In the sequences, contiguous occurrences of even numbers are forbidden.

For example for $x=5, n=4$:

1,4,7,9 is a valid sequence

1,2,4,7 is not a valid sequence

I need to find the recurrence relation for such sequence and to solve the characteristic equation for the recurrence.

If the first number in the sequence is odd the next number can be even or odd, thus $t_{odd}(n)=t_{odd}(n-1)+t_{even}(n-1)$.

If the first number is even the next number must be odd thus: $t_{even}(n) = \frac{x}{2}t_{even}(n-2)+\frac{x}{2}t_{odd}(n-2)$ because the next number must be one of $\frac{x}{2}$ odd numbers.

I'm not sure if I'm on the right track and if I am I don't understand how to combine the two cases in order to solve the characteristic equation.

$\endgroup$
1
  • $\begingroup$ Hint: any such string (of length at least $2$) either ends in an odd or in an even preceded by an odd. $\endgroup$
    – lulu
    Commented May 12, 2018 at 12:33

1 Answer 1

1
$\begingroup$

You're on the right general track, but there are some small algebraic mistakes.

First, note that the number of odd digits (or the number of even digits) is $x$, not $x/2$, since the total number of digits is $2x$; basically, the division by 2 that you're using in your current (incorrect) formula for $t_{even}$ has already been 'baked in' for you. Likewise, the number of even digits is $x+1$ : $0, 2, \ldots, 2x$ (there's a sneaky off-by-one problem lurking here, one that I've made a couple of times already in this answer and its comments!)

Second and more critically, there are errors in both your terms because you're missing a factor of $x$. In your $t_{odd}$ term, you're right about the ways it can break down but forgot that there can be $x$ different 'next digits'; you make the same mistake in your $t_{even}$ term, one layer removed. Try working through your tentative recurrences in the case $n=3, x=2$ (so there are 5 digits) to see what I mean.

Once you take these factors into account, you'll have an expression for $t_{odd}(n)$ in terms of a constant factor times $(t_{odd}(n-1)+t_{even}(n-1))$, and likewise an expression for $t_{even}(n)$ in terms of a constant factor times $(t_{odd}(n-2)+t_{even}(n-2))$; now just add them, set $u(n)=t_{odd}(n)+t_{even}(n)$, and note that this lets you write $u(n)$ in terms of $u(n-1)$ and $u(n-2)$.

Note that you can get at the same result somewhat more directly; let $u(n)$ be the number of such strings with $n$ digits (i.e., $u(n)=t_{odd}(n)+t_{even}(n)$.) Then as you already noticed, if $u(n)$ begins with an odd digit, the rest of the sequence can be arbitrary, while if $u(n)$ begins with an even digit, the next digit must be odd but the rest can be arbitrary; in other words, $u(n) = \{\#$of ways the first digit can be odd$\}\cdot u(n-1)+\{\#$of ways the first digit can be even$\}\cdot\{\#$of ways the second digit can be odd$\}\cdot u(n-2)$, and all of the bracketed expressions should be easy.

$\endgroup$
11
  • $\begingroup$ following your suggestions $t_{even}(n) = x(t_{odd}(n-2)+t_{even}(n-2))$ but if we want to add $x$ to calculate $t_{odd}$ then I think it's like this: $t_{odd}(n)=x(t_{odd}(n-2)+t_{even}(n-2))$. But then $t_{odd}(n)=t_{even}(n)$ but this doesn't work because for $x=1, n=2$ I have $t_1=3, t_2=5,t_3=11$ $\endgroup$
    – Yos
    Commented May 12, 2018 at 13:21
  • 1
    $\begingroup$ Both of those are slightly incorrect. Try this: first write $t_{even}(n)$ in terms of $t_{odd}(n-1)$, and write $t_{odd}(i)$ in terms of $t_{even}(i-1)+t_{odd}(i-1)$. What are your formulas in each of those cases? $\endgroup$ Commented May 12, 2018 at 13:26
  • 1
    $\begingroup$ @Yos That looks correct to me, yes! $\endgroup$ Commented May 12, 2018 at 14:17
  • 1
    $\begingroup$ (Note that you have to be a little careful with your base cases and it's best not to do those until you've already got the recurrence in 'combined' form; by convention you would have either $t_{odd}(0)=1$ and $t_{even}(0)=1$, or $t_{odd}(0)=t_even{0}=0$, but $u(0)=1\neq t_{odd}(0)+t_{even}(0)$! ) $\endgroup$ Commented May 12, 2018 at 14:28
  • 1
    $\begingroup$ I just realized the problem with this - there are $x$ odd numbers between 0 and $2x$ (inclusive), but $x+1$ even numbers. This changes the formulas slightly, but the idea should be the same. $\endgroup$ Commented May 12, 2018 at 17:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .