2

My thought : Total $n$ letter words that can be formed by repeating $4$ letters is number of onto functions from set of $n$ elements to set of $4$ elements.

This is equal to $4^n-4\times 3^n+6\times 2^n-4$. But I cannot count how many times a and b will come together. Please help.

RobPratt
  • 45,619
user1991
  • 379
  • Why must it be an onto function? IE Isn't $aaaa$ valid for $n = 4$? – Calvin Lin Jun 09 '21 at 20:13
  • Yeah, the alphabet, in such problems, don’t usually require you to use all letters. – Thomas Andrews Jun 09 '21 at 20:17
  • It seems like you can define this recursively, if you don’t require all letters. – Thomas Andrews Jun 09 '21 at 20:19
  • I can offer an answer but not a proof.

    Let $\alpha=\frac{3+\sqrt{17}}{2}$ and $\beta=\frac{3-\sqrt{17}}{2}$. These are the two roots of $x^2-3x-2$. Then the number of such words of length $n$ is $f(n)=\frac{5}{2\sqrt{17}}\left(\alpha ^n-\beta ^n\right)+\frac{1}{2} \left(\alpha ^n+\beta ^n\right.$

    Alternatively, $f(n)$ satisfies $f(n)=3f(n-1)+2f(n-2)$ with $f(1)=4$ and $f(2)=14$.

    – pancini Jun 09 '21 at 22:54

2 Answers2

1

Assuming you don’t have to use all the letters, then let $A_n$ be the number of such words that end in $a$ or $b,$ and $C_n$ be the words that don’t. Then $A_0=0,C_0=1,$ and $$A_{n+1}=A_n+2C_{n}\\C_{n+1}=2A_n+2C_n$$

Or:

$$\begin{pmatrix}A_n\\C_n\end{pmatrix}=\begin{pmatrix}1&2\\2&2\end{pmatrix}^n\begin{pmatrix}0\\1\end{pmatrix}$$

The number you want is $D_n=A_n+C_n.$ You can get a closed formula by diagonalizing the matrix, or by representing the $(0,1)^T$ as a sum of eigenvectors of the matrix.

You can get a linear recurrence:

$$D_{n+1}=3D_n+2D_{n-1}, D_0=1,D_1=4$$

You can find a direct argument for that recurrence.

The exact answer I get is:

$$D_n=\frac{17+5\sqrt{17}}{34}\left(\frac{3+\sqrt{17}}2\right)^n+ \frac{17-5\sqrt{17}}{34}\left(\frac{3-\sqrt{17}}2\right)^n$$

Which can also be written as the nearest integer to: $$\frac{17+5\sqrt{17}}{34}\left(\frac{3+\sqrt{17}}2\right)^n\approx 1.106\cdot 3.562^n$$

If you really must use all the letters, you’ll need to add this sort of computation to an inclusion-exclusion argument. You’ll have to use a similar argument for subtracting the case when one of $c$ or $d$ is not in the string.

Thomas Andrews
  • 177,126
  • @ Thomas Andrews Thanks for the help. Can you please suggest any book or material introducing such technique of recurrence? I am intrigued.. – user1991 Jun 09 '21 at 21:31
  • @user1991 See the Addendum to my answer which shows my unsuccessful attempt to convert a recurrence formula into a closed form expression. As far as my own analytical approach to recurrence, it is about 4 parts intuition to 1 part algebra, as demonstrated in my answer. – user2661923 Jun 09 '21 at 22:02
  • 1
    For the direct argument: $3D_{n}$ counts the sequences of length $n+1$ which do not end in $cd$ or $dc$, while $2D_{n-1}$ counts sequences of length $n+1$ ending in $cd$ or $dc$. – Mike Earnest Jun 09 '21 at 22:11
  • +1 to your answer. Very surprising that I should find my answer given a score of $+1$, while your answer remains at a score of $0$. Especially since, as I noted in my Addendum, my answer can be construed as incomplete, while you were (somehow) able to generate a closed form expression. – user2661923 Jun 10 '21 at 04:26
  • @Bulbasaur In your answer, the first thing that I noted is "Let say that $n$ length string end up with $a$ and do not have $a$ and $b $ together , so there are $a_{n-1}$ such strings." I assume that in general, $a_k$ denotes how many satisfying strings, there are of length $k$. If this is wrong, please advise. Assuming so, if I am interpreting your assertion correctly, the assertion is wrong because the $(n-1)$-length string could end in $b$. So, for some portion of the $(n-1)$-length strings, adding $a$ to the tail end will violate the constraint. ...see next comment – user2661923 Jun 10 '21 at 10:09
  • @Bulbasaur Three pieces of advice: [1] At the start of your answer, it was unclear to me what you are saying. It would be nice if your analysis was so crystal clear that no one was confused re your intent. [2] When you are considering an assertion, it is a good idea to sanity check it by working through small values of $n$, to see if the assertion holds in those cases. [3] Either the analysis in my answer has an error, or it doesn't. If you can't find an error in my analysis, then you have to be concerned if your answer does not match mine. – user2661923 Jun 10 '21 at 10:13
1

I agree with Calvin Lin's comment. That is, the starter enumeration is $4^n$.

Also, I reject the Inclusion-Exclusion approach as being to unwieldy, given that a formula is required for the generic value of $n$. For a small explicit value of $n$, I would have more strongly considered Inclusion-Exclusion.

Highjacking the insight from the comment of Thomas Andrews, I will use recursion.

For $n=2$, the number of satisfying words is $(4^2) - 2.$
To investigate the use of recursion, I must enumerate how many of the $(14)$ satisfying $2$-letter words end in $a$ or $b$, and how many do not.

If the last character is $a$ or $b$, then, in the satisfying word, there are 3 choices for the first character. Therefore, there are $6$ satisfying $2$-letter words that end in $a$ or $b$. Similarly, if the last character is $c$ or $d$, then the first character is unconstrained. Therefore, there are $8$ satisfying $2$-letter words that end in $c$ or $d$.

Let $T_n$ denote the number of satisfying words of length $n$.
Let $S_n$ denote the number of satisfying words of length $n$ that end in either $a$ or $b$.
Let $R_n$ denote the number of satisfying words of length $n$ that end in either $c$ or $d$.

Then, in general, you have that $R_n + S_n = T_n$.

In particular, you have that $R_2, S_2, T_2 = 8, 6, 14,$ respectively.

The challenge is to find the formulas for $R_{n+1}, S_{n+1}, T_{n+1}$ in terms of $R_n, S_n, T_n$.

My approach is to enumerate $R_3, S_3, T_3$, and then use this to derive the necessary formulas.

The $(R_2 = 8)$ two-letter words can be followed either by one of $a,b$ or not.

Therefore, a starter-running-total for the enumeration of $R_3, S_3$ is $R_3 = 2 \times R_2, ~~S_3 = 2 \times R_2$.

The $(S_2 = 6)$ two-letter words can either be followed by $c,d$ or by the $(a,b)$ letter that matches the 2nd letter used.

Therefore, the incremental addition to $R_3, S_3$ generated by extending the $6$ two-letter words is $R_3 = R_3 + (2 \times S_2), ~~ S_3 = S_3 + S_2$

Putting this all together, this implies that:

  • $R_3 = (2R_2) + (2S_2) = 2T_2$.
  • $S_3 = (2R_2) + S_2 = 2T_2 - S_2.$
  • $T_3 = (2T_2) + (2T_2 - S_2) = 4T_2 - S_2$.

The nice thing about the above analysis, is that it is independent of $n$.

So, in general:

  • $S_{n+1} = 2T_n - S_n$
  • $T_{n+1} = 4T_n - S_n$.

Based on the above formulas, you can immediately generate the following chart:

\begin{array}{| r | r | r |} \hline n & S_n & T_n \\ \hline 2 & 6 & 14 \\ \hline 3 & 22 & 50 \\ \hline 4 & 78 & 178 \\ \hline 5 & 278 & 634 \\ \hline \end{array}


Addendum
A very good case can be made that my answer is incomplete. That is, what is really desired is a closed form expression. Although I was not able to generate such an expression, I can at least demonstrate the attempt that I made.

$S_{n+1} = 2T_n - S_n.$
$T_{n+1} = 4T_n - S_n.$

This leads to
$S_{n+2} = 6T_n - S_n.$
$T_{n+2} = 14T_n - 3S_n.$

This leads to
$S_{n+3} = 22T_n - 5S_n.$
$T_{n+3} = 50T_n - 11S_n.$

Personally, I was not able to find an elegant algebraic expression for $S_{n+k}, T_{n+k}$ in terms of $k$. If I had been able to, I would have then plugged in the values of $S_2, T_2 = 6, 14.$

user2661923
  • 35,619
  • 3
  • 17
  • 39
  • please check now – Not a Salmon Fish Jun 10 '21 at 10:24
  • @Bulbasaur I am still having trouble following your analysis. Also, I am unfamiliar with the goulden-cluster method. Perhaps, you could include a description of this method in your answer. Also, from what I can see, your work is still confusing and the assertion at the start of your answer, which I think is wrong, is unchanged. Also, I am serious about asking you to look for an error in my analysis. Finally, if you are able to write a computer program (e.g. in Java, C, python, ...), then you can sanity-check whatever answer you compute, via your computer program. – user2661923 Jun 10 '21 at 10:33
  • description of goulden -cluster method : https://math.stackexchange.com/questions/4096861/finding-recurrence-relation-that-contain-and-do-not-contain-122-in-the-alphabe . By the way i think that you are making overcounting when $n \geq 2$ . – Not a Salmon Fish Jun 10 '21 at 13:29
  • nope , i my result agree with $a_2=14$ – Not a Salmon Fish Jun 10 '21 at 13:42
  • $ab$ and $ba$ both are bads – Not a Salmon Fish Jun 10 '21 at 13:42
  • i guess we can solve my problem by writing all bad cases for n=3 , let me write them – Not a Salmon Fish Jun 10 '21 at 13:53
  • yours is right , i make mistake in calculating , i just realize .sorry for false alarm – Not a Salmon Fish Jun 10 '21 at 13:59