Lets consider the $n-$ strings over the alphabet $\color{purple}{\{0,1,2,3,4\}}$ that
$\color{blue}{a-)}$ do not contain the substring $\color{green}{122}$ such that $1334211112$ is allowed but $..44311 $$\color{red}{122}$ $344..$ is not allowed.
$\color{blue}{b-)}$ contain the substring $\color{green}{122}$
I am trying to find the recurrence relation of $n$ strings that satisfies the desired conditions respectively.I found recurrence relations but i am not sure whether they are true or not .
$\color{BROWN}{SOLUTION:}$
$\color{blue}{a-)}$ We know that this $n$ lenght strings will end up with either $0$ or $1$ or $2$ or $3$ or $4$.
Lets say that the string ends with $0$ and does not contain $122$ , so there are $a_{n-1}$ such strings.
Lets say that the string ends with $1$ and does not contain $122$ , so there are $a_{n-1}$ such strings.
Lets say that the string ends with $2$ and does not contain $122$ , so there are $a_{n-1}$ such strings.
Lets say that the string ends with $3$ and does not contain $122$ , so there are $a_{n-1}$ such strings.
Lets say that the string ends with $4$ and does not contain $122$ , so there are $a_{n-1}$ such strings.
So, there are $5a_{n-1}$ such strings that do not contain $122$ , but let us think about the string which end with $2$ and do not contain $122$. It has $a_{n-1}$ string that do not have $122$ , but this $a_{n-1}$ string might end with $12$. Because of this, we must subtract the sequence which end up with $2$ and have a substring with lengh $n-1$ but end with $12$.
Hence , the solution is $a_n=5a_{n-1}-a_{n-3}$
$\color{blue}{b-)}$ We know that this $n$ lenght strings will end up with either $0$ or $1$ or $2$ or $3$ or $4$.
Lets say that the string ends with $0$ and contains $122$ , so there are $a_{n-1}$ such strings.
Lets say that the string ends with $1$ and contains $122$ , so there are $a_{n-1}$ such strings.
Lets say that the string ends with $02$ and contains $122$ , so there are $a_{n-2}$ such strings.
Lets say that the string ends with $12$ and contains $122$ , so there are $a_{n-2}$ such strings.
Lets say that the string ends with $022$ and contains $122$ , so there are $a_{n-3}$ such strings.
Lets say that the string ends with $122$ , so there are $5^{n-3}$ such strings.
Lets say that the string ends with $322$ and contains $122$ , so there are $a_{n-3}$ such strings.
Lets say that the string ends with $422$ and contains $122$ , so there are $a_{n-3}$ such strings.
Lets say that the string ends with $32$ and contains $122$ , so there are $a_{n-2}$ such strings.
Lets say that the string ends with $42$ and contains $122$ , so there are $a_{n-2}$ such strings.
Lets say that the string ends with $3$ contains $122$ , so there are $a_{n-1}$ such strings.
Lets say that the string ends with $4$ contains $122$ , so there are $a_{n-1}$ such strings.
$\therefore a_n=4a_{n-1}+4a_{n-2}+3a_{n-3}+5^{n-3}$
Is my solution correct ? Moreover , if you know another approach to this solution , can you share your knowledge with me ?
What's more , do you know any book or website to find these types of exercises to improve myself ?

Here we derive a recurrence relation for (a) and (b) based upon a generating function approach, the so-called Goulden-Jackson Cluster Method.
Case (a):
According to the paper (p.7) the generating function $A(z)$ is \begin{align*} A(z)=\frac{1}{1-dz-\text{weight}(\mathcal{C})}\tag{1} \end{align*} with $d=|\mathcal{V}|=5$, the size of the alphabet and $\mathcal{C}$ the weight-numerator of bad words with \begin{align*} \text{weight}(\mathcal{C})=\text{weight}(\mathcal{C}[122]) \end{align*} We calculate according to the paper \begin{align*} \text{weight}(\mathcal{C})=\text{weight}(\mathcal{C}[122])&=-z^3\\ \end{align*}
We recall if a generating function has a representation as rational function of the form \begin{align*} A(z)=\sum_{n=0}^\infty a_n z^n=\frac{P(z)}{Q(z)} \end{align*} with $P(z), Q(z)$ polynomials, $\deg Q=q>\deg P$ and \begin{align*} Q(z)=1+\alpha_1 z+\alpha_2 z^2+\cdots + \alpha_q z^q \end{align*} then the coefficients $a_n$ follow the recurrence relation \begin{align*} a_{n+q}+\alpha_1 a_{n+q-1}+\alpha_2 a_{n+q-2}+\cdots +\alpha_q a_{n}=0\qquad\qquad n\geq 0 \end{align*} See for instance theorem 4.1.1 in Enumerative Combinatorics, Vol. I by R. P. Stanley.
Case (b):
We derive a recurrence relation for all words of length $n\geq 0$ built from the alphabet $$\mathcal{V}=\{0,1,2,3,4\}$$ which do contain the word $122$ with the help from case (a).
Thanks to the the theorem above we find from (3) the recurrence relation \begin{align*} b_{n+4}-10b_{n+3}+25b_{n+2}+b_{n+1}-5b_n=0\qquad\qquad n\geq 0 \end{align*} resp. by shifting the indices we get