It was asked of me to count all ternary strings with size $n$, such that each element $\{a,b,c\}$ occurs at least once in the string. Exercise specific, it was when $n=5$, but I'm looking on building a recurrence relation now.
I approached the problem by counting with labeled distribution i.e. $\frac{n!}{n_1!n_2!n_3!}$, for all possible $n_k$'s in $n=5$, which are either with $2$ repetitions and $1$ single letter, or $3$ repetitions and $2$ single letters. So for $5$ elements, it's $3 \cdot \frac{5!}{3!} + 3 \cdot \frac{5!}{2!2!}$. I'm not sure if I'm correct, because I'm not sure if I'm taking all cases into consideration.
Another way I thought of would be counting all the strings with only $2$ elements and subtract them from the number of all strings which is $3^5$, for this case.
I'll now be looking into in how to build a recurrence relation, and check my previous solution. I haven't found the same question in this forum. Any insight is appreciated!
P.S. This was an exam question. I am now checking my answers.
There are three ways to fill each of the $n$ positions without restriction, so there are $3^n$ ternary strings of length $n$. From these, we must subtract those cases in which fewer than three letters are used in the string.
There are $3$ ways to exclude one of the letters from the string and $2^n$ ways to fill the $n$ positions with the remaining two letters. However, if we subtract $3 \cdot 2^n$ from $3^n$, we will have subtracted too much since we will have subtracted the three strings in which two letters are excluded twice, once for each way we could have excluded one of the two missing letters. Since we only want to subtract such strings once, we must add them back. Therefore, by the Inclusion-Exclusion Principle, the number of ternary strings of length $n$ in which each letter appears at least once is $$3^n - \binom{3}{1}2^n + \binom{3}{2}1^n = 3^n - 3 \cdot 2^n + 3$$