# Thread:

1. ## Recurrence relation problem

Find a recurrence relation for the number of ternary strings (0 s, 1 s and 2 s) of length n that contain none of the strings 101, 202, 102, or 201. What are the initial conditions? Use the recurrence to compute the number of such sequences of length 5.

I am trying this for the past 7 days. Please help me in solving this. help would be greatly appreciated.

2. Originally Posted by kkkkkk
Find a recurrence relation for the number of ternary strings (0 s, 1 s and 2 s) of length n that contain none of the strings 101, 202, 102, or 201. What are the initial conditions? Use the recurrence to compute the number of such sequences of length 5.
Let $a_n$ be the number of such strings of length n. Now think about how to construct a string of length n+1 by taking such a string, call it s, and adding an additional number at the end of s. If s ends in a 1 or a 2 then we can add any of 0,1,2 and still have an allowable string. But if s ends in a 0 we need to look at the last two elements of s. If they are 00, we can add anything and still have an allowable string. But if s ends in 10 or 20 then we have to add a 0 as the (n+1)th element.

Another way to say that is that we can add a 0 to any string and still have an allowable string. But we have to be more careful about adding a 1 or a 2.

So the number of strings of length n ending in a 0 is $a_{n-1}$ and therefore the number ending in a 1 or a 2 is $a_n-a_{n-1}$.

Now, how many strings of length n+1 are there? For each of the $a_{n-1}$ n-strings ending in a 0 we can get three (n+1)-strings. For each of the $a_{n-2}$ n-strings ending in 00 we can also get three (n+1)-strings. But for each of the $a_{n-1} - a_{n-2}$ n-strings ending in x0 (where x = 1 or 2) we can only get one (n+1)-string. Take that information and make it into a recurrence relation.

3. thankyou for your great help

I would appreciate it.

But Finding the recurrence relation was a great difficulty. So, can you suggest me the sequence so that I can make a recurrence relation because I couldn't follow the sequence.

4. Just to add : The initial conditions are :
a1 = 3
a2 = 9
a3 = 23

5. thanks for u r help. But I couldn't establish the recurrence relation. I tried some. They were working for 1 and 2 but not from 3. So, suggest a recurrence relation that would work for all

6. If i am not wrong the recurrence relation is $a_n = a_{n-1}+4a_{n-2}+2a_{n-3}$.

7. Originally Posted by tester85
If i am not wrong the recurrence relation is $a_n = a_{n-1}+4a_{n-2}+2a_{n-3}$.
The relation I arrived at (following my previous hints) is $a_n = 3a_{n-1}-2a_{n-2}+2a_{n-3}$. With the initial conditions $a_1=3$, $a_2=9$, $a_3=23$, that gives the prediction $a_4=57$, which agrees with what I get by a direct count.

8. thank u very much for u r help. I will appreciate it greatly.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 13, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.943683385848999, "perplexity_flag": "head"}