2

how do i solve this recursive question:

In how many sequences of length n that are made of the numbers{0,1,2,3} there are without the substrings 00,11,22,33,03,30

i need a recursive answer, can someone help me resolve this question and give me some example? thanks!

  • 2
    separate into sequences of type A which end in $0$ or $3$, and type B which end in $1$ or $2$. – Joffan Dec 23 '16 at 21:31
  • this is the right one: an = 2Bn-1 + 2An-1 ,An=2Bn-1 ,Bn=Bn-1+2An-1? cant edit my comment for some reason – user401566 Dec 23 '16 at 22:12

2 Answers2

0

Hint: Let $a_n$ be the number of sequences (usually called words) from $\{0,1,2,3\}$, with the named exclusions. Let $w$ be such a word of length $n$. The last digit is either $0$, $1$, $2$, or $3$.

  • If the last digit is $0$, the next-to-last digit cannot be $0$ or $3$, because sequences of $00$ or $30$ are not allowed. But it could be $1$ or $2$. The $n-2$ digits before constitute an admissible word of length $n-2$. So there are $2 a_{n-2}$ words of length $n$ that end in $0$.

  • continue...

  • Or are there? I just noticed that if the next-to-last digit is 1, the one before that can't be 1, too. So it might be more subtle than that. Still, this is the general idea, which is what you asked for. – Matthew Leingang Dec 23 '16 at 21:37
  • thanks for the quick answer, i know the general idea of how to solve those problems but this one i just cant get right – user401566 Dec 23 '16 at 22:03
0

For future reference the DFA Method yields the following transcript. The reader may then compare the data from a combinatorial solution to the series (OGF) that was output from the main routine.

> GFNC([[0,0], [1,1], [2,2], [3,3], [0,3], [3,0]], 4,true);
                [[3, 0], [0, 3], [3, 3], [2, 2], [1, 1], [0, 0]]

                                  Q[], 0, Q[0]

                                  Q[], 1, Q[1]

                                  Q[], 2, Q[2]

                                  Q[], 3, Q[3]

                                Q[0], 0, Q[0, 0]

                                 Q[0], 1, Q[1]

                                 Q[0], 2, Q[2]

                                Q[0], 3, Q[0, 3]

                              Q[0, 0], 0, Q[0, 0]

                              Q[0, 0], 1, Q[0, 0]

                              Q[0, 0], 2, Q[0, 0]

                              Q[0, 0], 3, Q[0, 0]

                              Q[0, 3], 0, Q[0, 3]

                              Q[0, 3], 1, Q[0, 3]

                              Q[0, 3], 2, Q[0, 3]

                              Q[0, 3], 3, Q[0, 3]

                                 Q[1], 0, Q[0]

                                Q[1], 1, Q[1, 1]

                                 Q[1], 2, Q[2]

                                 Q[1], 3, Q[3]

                              Q[1, 1], 0, Q[1, 1]

                              Q[1, 1], 1, Q[1, 1]

                              Q[1, 1], 2, Q[1, 1]

                              Q[1, 1], 3, Q[1, 1]

                                 Q[2], 0, Q[0]

                                 Q[2], 1, Q[1]

                                Q[2], 2, Q[2, 2]

                                 Q[2], 3, Q[3]

                              Q[2, 2], 0, Q[2, 2]

                              Q[2, 2], 1, Q[2, 2]

                              Q[2, 2], 2, Q[2, 2]

                              Q[2, 2], 3, Q[2, 2]

                                Q[3], 0, Q[3, 0]

                                 Q[3], 1, Q[1]

                                 Q[3], 2, Q[2]

                                Q[3], 3, Q[3, 3]

                              Q[3, 0], 0, Q[3, 0]

                              Q[3, 0], 1, Q[3, 0]

                              Q[3, 0], 2, Q[3, 0]

                              Q[3, 0], 3, Q[3, 0]

                              Q[3, 3], 0, Q[3, 3]

                              Q[3, 3], 1, Q[3, 3]

                              Q[3, 3], 2, Q[3, 3]

                              Q[3, 3], 3, Q[3, 3]

                                     2
                                  2 z  + 3 z + 1
                                - --------------
                                      2
                                   4 z  + z - 1

> series(%, z, 13);
              2       3       4        5        6         7         8         9
1 + 4 z + 10 z  + 26 z  + 66 z  + 170 z  + 434 z  + 1114 z  + 2850 z  + 7306 z

              10          11           12      13
     + 18706 z   + 47930 z   + 122754 z   + O(z  )

Here is the sequence one more time: $$1, 4, 10, 26, 66, 170, 434, 1114, 2850, 7306,\ldots$$

The surprising part is that this sequence even has an entry at the OEIS, A277236.

Remark. We do not require the full mechanics of the DFA method here as we can simply classify admissible words according to the last digit. This yields a system of four linear equations in four variables. These can then be solved and the answer is the same as from the DFA method, see below.

> solve([A0-z=z*(A1+A2), A1-z=z*(A0+A2+A3\
> ), A2-z=z*(A0+A1+A3), A3-z=z*(A1+A2)], [A0,A1,A2,A3]);
          z (z + 1)           z (2 z + 1)          z (2 z + 1)
[[A0 = - ------------, A1 = - ------------, A2 = - ------------,
            2                    2                    2
         4 z  + z - 1         4 z  + z - 1         4 z  + z - 1

            z (z + 1)
    A3 = - ------------]]
              2
           4 z  + z - 1

> subs(op(1, %), A0+A1+A2+A3);
                           2 z (z + 1)    2 z (2 z + 1)
                         - ------------ - -------------
                              2              2
                           4 z  + z - 1   4 z  + z - 1

> simplify(1+%);
                                     2
                                  2 z  + 3 z + 1
                                - --------------
                                      2
                                   4 z  + z - 1

Remark, II. Simplifying even more we may establish a system of only two equations by classifying words according to whether they and in zero or three or one or two. It looks like this is what the question is asking for, and it is shown below.

> solve([A03-2*z=2*z*A12, A12-2*z=2*z*A03+z*A12], [A03, A12]);
                          2 z (z + 1)           2 z (2 z + 1)
                [[A03 = - ------------, A12 = - -------------]]
                             2                     2
                          4 z  + z - 1          4 z  + z - 1

> subs(op(1, %), A03+A12);
                           2 z (z + 1)    2 z (2 z + 1)
                         - ------------ - -------------
                              2              2
                           4 z  + z - 1   4 z  + z - 1

> simplify(1+%);
                                     2
                                  2 z  + 3 z + 1
                                - --------------
                                      2
                                   4 z  + z - 1
Marko Riedel
  • 61,317