8

I have the following question:

We are going to generate permutations from a,a,b,b,b,c,c,c,c. Please compute the number of permutations such that:
(a) for any consecutive 4 elements, they are not all the same;
(b) for any consecutive 3 elements, they are not all the same;
(c) for any consecutive 2 elements, they are not all the same.


See Arrangements of $a,a,b,b,b,c,c,c,c$ in which no four/three/two consecutive letters are the same for the first two parts.

I got an answer for part c but I am not sure if it is correct or not. My step is the following.
I found that there are six pairs containing adjacent identical letters. I will define them as$S_1, S_2,..., S_6$ the small number is the number of pairs of adjacent identical letters. $$S_0 =\binom{9}{2,3,4}$$

$$S_1 =\binom{8}{3,4} + \binom{8}{2,4} + \binom{8}{2,3,2}$$ $$S_2 = \frac{7!}{4!}+\binom{7}{3,2}+\binom{7}{4,2} + \binom{7}{3,2} + \binom{6}{3,2}+\binom{7}{2,2}$$ $$S_3 = \frac{6!}{4!}+\frac{6!}{3!}+\frac{5!}{3!} + \binom{6}{2,2} + \frac{6!}{2!} + \frac{5!}{2!}$$ $$S_4 = \frac{5!}{2!}+\frac{5!}{3!}+\frac{5!}{2!} + \frac{5!}{2!} + {5!}+{4!}$$ $$S_5 = {4!}+{3!}+\frac{4!}{2!} $$ $$S_6 = 3!$$
I sum these up by the inclusion-exclusion principle, and I got the answer of the following:
$$N = S_0 - S_1+ S_2- S_3 +S_4 -S_5+ S_6 = 473$$
I want to know if there is any miscalculation or if the wrong steps exist. Could anyone please help?

N. F. Taussig
  • 76,571
Louis.
  • 307

5 Answers5

5

Such problems become intractable very rapidly, I prefer to use a form of the generalized Laguerre polynomial as described by Jair Taylor

Define polynomials for $k\geq 1$ by $q_k(x) = \sum_{i=1}^k \frac{(-1)^{i-k}}{i!} {k-1 \choose i-1}x^i$.

The number of permutations will be given by

$$\int_0^\infty \prod_j q_{k_j}(x)\, e^{-x}\,dx.$$

We get $q_2(x) = (x^2-2x)/2!$
$q_3(x) = (x^3-6x^2+6x)/3!$
$q_4(x) = (x^4-12x^2+36x^2-24x)/4!$

Using the above method, I get an answer of 79

4

Let's correct your attempt. You made a systematic error, namely omitting cases with two disjoint pairs of adjacent $c$s. While most of your other terms are correct, there are some cases where you made computational errors. Since you did not explicitly state your cases, you will have to compare your terms with mine in order to identify those errors.

Also, I recommend including the $1$s in your multinomial coefficients both to avoid confusion with binomial coefficients and to make it easier to keep track of the number of objects.

A multinomial coefficient $$\binom{n}{n_1, n_2, n_3, \cdots, n_k} = \frac{n!}{n_1! n_2 ! n_3! \cdots n_k!}$$ counts the number of distinguishable ways to arrange $n = n_1 + n_2 + n_3 + \cdots + n_k$ objects in a row if there are $n_1$ objects of type $1$, $n_2$ objects of type $2$, $n_3$ of type $3$, and so forth.

Since you appear to be using $S_i$ to denote arrangements with $i$ pairs of adjacent identical letters, I will denote the total number of arrangements by $S$ rather than $S_0$, since $S_0$, the number of arrangements with no pairs of adjacent identical letters, is what we want to find.

$S$: There are nine positions to fill, of which two are $a$s, three are $b$s, and four are $c$s. They can be filled in $$|S| = \binom{9}{2}\binom{7}{3}\binom{4}{4} = \frac{9!}{2!3!4!} = \binom{9}{2, 3, 4}$$ ways since we must choose two of the nine positions for the $a$s, three of the remaining seven positions for the $b$s, and all four of the remaining four positions for the $c$s.

$S_1$: Your counts are all correct.

A pair of adjacent $a$s: We have eight objects to arrange: $aa, b, b, b, c, c, c, c$. They can be arranged in $$\binom{8}{1, 3, 4}$$ ways.

A pair of adjacent $b$s: We have eight objects to arrange: $a, a, bb, b, c, c, c, c$. They can be arranged in $$\binom{8}{2, 1, 1, 4}$$ ways.

A pair of adjacent $c$s: We have eight objects to arrange: $a, a, b, b, b, cc, c, c$. They can be arranged in $$\binom{8}{2, 3, 1, 2}$$ ways.

Hence, $$|S_1| = \binom{8}{1, 3, 4} + \binom{8}{2, 1, 1, 4} + \binom{8}{2, 3, 1, 2}$$

$S_2$: You should have seven objects in all cases.

A pair of adjacent $a$s and a pair of adjacent $b$s: There are seven objects to arrange: $aa, bb, b, c, c, c, c$. They can be arranged in $$\binom{7}{1, 1, 1, 4}$$ ways.

A pair of adjacent $a$s and a pair of adjacent $c$s: There are seven objects to arrange: $aa, b, b, b, cc, c, c$. They can be arranged in $$\binom{7}{1, 3, 1, 2}$$ ways.

Two overlapping pairs of adjacent $b$s: There are seven objects to arrange: $a, a, bbb, c, c, c, c$. They can be arranged in $$\binom{7}{2, 1, 4}$$ ways.

A pair of adjacent $b$s and a pair of adjacent $c$s: There are seven objects to arrange: $a, a, bb, b, cc, c, c$: They can be arranged in $$\binom{7}{2, 1, 1, 1, 2}$$ ways.

Two overlapping pairs of adjacent $c$s: There are seven objects to arrange: $a, a, b, b, b, ccc, c$. They can be arranged in $$\binom{7}{2, 3, 1, 1}$$ ways. Notice that $2 + 3 + 1 + 1 = 7$, which is a good way of checking whether you have the correct number of terms.

Two disjoint pairs of adjacent $c$s: There are seven objects to arrange: $a, a, b, b, b, cc, cc$. They can be arranged in $$\binom{7}{2, 3, 2}$$ ways.

Hence, $$S_2 = \binom{7}{1, 1, 1, 4} + \binom{7}{1, 3, 1, 2} + \binom{7}{2, 1, 4} + \binom{7}{2, 1, 1, 1, 2} + \binom{7}{2, 3, 1, 1} + \binom{7}{2, 3, 2}$$

$S_3$: You should have six objects in all cases.

A pair of adjacent $a$s and two overlapping pairs of adjacent $b$s: We have six objects to arrange: $aa, bbb, c, c, c, c$. They can be arranged in $$\binom{6}{1, 1, 4}$$ ways.

A pair of adjacent $a$s, a pair of adjacent $b$s, and a pair of adjacent $c$s: We have six objects to arrange: $aa, bb, b, cc, c, c$. They can be arranged in $$\binom{6}{1, 1, 1, 1, 2}$$ ways.

A pair of adjacent $a$s and two overlapping pairs of adjacent $c$s: We have six objects to arrange: $aa, b, b, b, ccc, c$. They can be arranged in $$\binom{6}{1, 3, 1, 1}$$ ways.

A pair of adjacent $a$s and two disjoint pairs of adjacent $c$s: We have six objects to arrange: $aa, b, b, b, cc, cc$. They can be arranged in $$\binom{6}{1, 3, 2}$$ ways.

Two overlapping pairs of adjacent $b$s and a pair of adjacent $c$s: We have six objects to arrange: $a, a, bbb, cc, c, c$. They can be arranged in $$\binom{6}{2, 1, 1, 2}$$ ways.

A pair of adjacent $b$s and two overlapping pairs of adjacent $c$s: We have six objects to arrange: $a, a, bb, b, ccc, c$. They can be arranged in $$\binom{6}{2, 1, 1, 1, 1}$$ ways.

A pair of adjacent $b$s and two disjoint pairs of adjacent $c$s: We have six objects to arrange: $a, a, bb, b, cc, cc$. They can be arranged in $$\binom{6}{2, 1, 1, 2}$$ ways.

Three overlapping pairs of adjacent $c$s: We have six objects to arrange: $a, a, b, b, b, cccc$. They can be arranged in $$\binom{6}{2, 3, 1}$$ ways.

Hence, $$|S_3| = \binom{6}{1, 1, 4} + \binom{6}{1, 1, 1, 1, 2}+ \binom{6}{1, 3, 1, 1} + \binom{6}{1, 3, 2} + \binom{6}{2, 1, 1, 2} + \binom{6}{2, 1, 1, 1, 1} + \binom{6}{2, 1, 1, 2} + \binom{6}{2, 3, 1}$$

$S_4$: You should have five objects in all cases.

A pair of adjacent $a$s, two overlapping pairs of adjacent $b$s, a pair of adjacent $c$s. We have five objects to arrange: $aa, bbb, cc, c, c$. They can be arranged in $$\binom{5}{1, 1, 1, 2}$$ ways.

A pair of adjacent $a$s, a pair of adjacent $b$s, and two overlapping pairs of adjacent $c$s: We have five objects to arrange: $aa, bb, b, ccc, c$. Since the objects are distinct, they can be arranged in $5!$ ways.

A pair of adjacent $a$s, a pair of adjacent $b$s, and two disjoint pairs of adjacent $c$s: We have five objects to arrange: $aa, bb, b, cc, cc$. They can be arranged in $$\binom{5}{1, 1, 1, 2}$$ ways.

A pair of adjacent $a$s and three overlapping pairs of adjacent $c$s: We have five objects to arrange: $aa, b, b, b, cccc$. They can be arranged in $$\binom{5}{1, 3, 1}$$ ways.

Two overlapping pairs of adjacent $b$s and two overlapping pairs of adjacent $c$s: We have five objects to arrange: $a, a, bbb, ccc, c$. They can be arranged in $$\binom{5}{2, 1, 1, 1}$$ ways.

Two overlapping pairs of adjacent $b$s and two disjoint pairs of adjacent $c$s: We have five objects to arrange: $a, a, bbb, cc, cc$. They can be arranged in $$\binom{5}{2, 1, 2}$$ ways.

A pair of adjacent $b$s and three overlapping pairs of adjacent $c$s: We have five objects to arrange: $a, a, bb, b, cccc$. They can be arranged in $$\binom{5}{2, 1, 1, 1}$$ ways.

Hence, $$|S_4| = \binom{5}{1, 1, 1, 2} + 5! + \binom{5}{1, 1, 1, 2} + \binom{5}{1, 3, 1} + \binom{5}{2, 1, 1, 1} + \binom{5}{2, 1, 2} + \binom{5}{2, 1, 1, 1}$$

$S_5$: You should have four objects in all cases.

A pair of adjacent $a$s, two overlapping pairs of adjacent $b$s, and two overlapping pairs of adjacent $c$s: We have four objects to arrange: $aa, bbb, ccc, c$. Since the objects are all distinct, they can be arranged in $4!$ ways.

A pair of adjacent $a$s, two overlapping pairs of adjacent $b$s, and two disjoint pairs of adjacent $c$s: We have four objects to arrange: $aa, bbb, cc, cc$. They can be arranged in $$\binom{4}{1, 1, 2}$$ ways.

A pair of adjacent $a$s, a pair of adjacent $b$s, and three overlapping pairs of adjacent $c$s: We have four objects to arrange: $aa, bb, b, cccc$. Since the objects are all distinct, they can be arranged in $4!$ ways.

Two overlapping pairs of adjacent $b$s and three overlapping pairs of adjacent $c$s. We have four objects to arrange: $a, a, bbb, cccc$. They can be arranged in $$\binom{4}{2, 1, 1}$$ ways.

Hence, $$|S_5| = 4! + \binom{4}{1, 1, 2} + 4! + \binom{4}{2, 1, 1}$$

$S_6$: You did this correctly.

A pair of adjacent $a$s, two overlapping pairs of adjacent $b$s, and two disjoint pairs of adjacent $c$s: We have three objects to arrange: $aa, bbb, cccc$. Since they are all distinct, they can be arranged in $$|S_6| = 3!$$ ways.

By the Inclusion-Exclusion Principle, the number of arrangements of $a, a, b, b, b, c, c, c, c$ in which no two adjacent letters are identical is $$|S| - |S_1| + |S_2| - |S_3| + |S_4| - |S_5| + |S_6| = 79$$ in agreement with the answer true blue anil obtained by using the more advanced technique of the generalized Laguerre polynomial.

N. F. Taussig
  • 76,571
  • @NFTaussig: +1 for your answer. I also decided to do this exercise manually, not realising that it is a bit tedious even with proper notation. Finally, it was helpful to also have your results available to check the validity of my contribution. – Markus Scheuer Nov 12 '22 at 18:40
  • 1
    @epi163sqrt Since I was familiar with your work and that of true blue anil, I found it reassuring that your answers matched mine. – N. F. Taussig Nov 13 '22 at 10:47
3

This answer is rather a supplement which could be used as crosscheck for manual calculations. We consider a $3$-ary alphabet built from letters $\mathcal{V}=\{a,b,c\}$. Words which do not have any consecutive equal letters are called Smirnov words. A generating function for Smirnov words is given as \begin{align*} \left(1-\frac{az}{1+az}-\frac{bz}{1+bz}-\frac{cz}{1+cz}\right)^{-1}\tag{1} \end{align*} The coefficient $[z^n]$ of $z^n$ in the series (1) gives the number of $3$-ary words of length $n$ which do not have any consecutive letters.

With some help of Wolfram Alpha we calculate the answer from (1) as \begin{align*} \color{blue}{[z^{9}a^2b^3c^4]\left(1-\frac{az}{1+az}-\frac{bz}{1+bz}-\frac{cz}{1+cz}\right)^{-1}=79} \end{align*}

Note: Smirnov words can be found for instance in example III.24 in Analytic Combinatorics by P. Flajolet and R. Sedgewick.

Markus Scheuer
  • 108,315
2

I already posted an answer using a form of Laguerre polynomials, but following @Jair Taylor's advice to try it manually, here is an effort avoiding the tortuous inclusion-exclusion.

If we first place the $a's$ and $b's$ in $\binom52=10$ ways, there is a maximum of $6$ spaces to place the $4\,c's$, which will reduce if one or more $c's$ need to be preplaced to separate contiguous $a's$ or $b's$

$.b.a.b.a.b.\;\; \binom64 =15$

$.a.b.a.b\bullet b.||\;.a.b\bullet b.a.b.||\;.b.a.b\bullet b.a.||\;.b\bullet b.a.b.a.\;$gives $4\times \binom53=40$

$.a.b\bullet b\bullet b.a.\;||\;.b.a\bullet a.b\bullet b.\;||\;.b\bullet b.a\bullet a.b.\;\; 3\times \binom42 = 18$

$.a\bullet a.b\bullet b\bullet b.\;||\;.b\bullet b\bullet b.a\bullet a.\;\; 2\times\binom31 = 6$

Total $= 79$, as before

  • 1
    This is a nice approach that a novice can understand. – N. F. Taussig Nov 09 '22 at 13:27
  • @N.F.Taussig: Thanks, after I posted the answer, I felt that using Laguerre polynomials or Smirnov words would give the correct answer immediately, but the means of calculating it might not be available to the student. – true blue anil Nov 09 '22 at 13:34
1

Here is an answer based upon PIE the principle of inclusion-exclusion. It is convenient to do some bookkeeping in order to cover all different cases. Here I use a notation slightly more compact as used in this post.

Problem: We want to count all words of length $9$ which are built from the letters $a,a,b,b,b,c,c,c,c$ which do not contain a bad word from $\mathcal{B}=\{aa,bb,cc\}$.

  • According to PIE we symbolically list all the different cases but indicating only the bad words in lexicographical order.

  • Different cases are separated by a vertical bar $|$.

  • Non-overlapping bad words are separated by space

  • $k$ overlapping bad words are given by $k+1$ consecutive letters as for instance $bbb$ indicating two overlapping bad words $bb$ or $cccc$ indicating three overlapping bad words $cc$.

We obtain \begin{align*}\color{blue}{ () }&\color{blue}{- (aa\ |\ bb\ |\ cc)}\\ &\color{blue}{+(aa\ bb\ |\ aa\ cc\ |\ bbb\ |\ bb\ cc\ |\ ccc\ |\ cc\ cc)}\\ &\color{blue}{-(aa\ bbb\ |\ aa\ bb\ cc\ |\ aa\ ccc\ |\ aa\ cc\ cc\ |\ bbb\ cc}\\ &\qquad\color{blue}{|\ bb\ ccc\ |\ bb\ cc\ cc\ |cccc)}\\ &\color{blue}{+(aa\ bbb\ cc\ |\ aa\ bb\ ccc\ |\ aa\ bb\ cc\ cc\ |\ aa\ cccc}\\ &\qquad\color{blue}{|\ bbb\ ccc\ |\ bbb\ cc\ cc\ |\ bb\ cccc)}\\ &\color{blue}{-(aa\ bbb\ ccc\ |\ aa\ bbb\ cc\ cc\ |aa\ bb\ cccc\ |\ bbb\ cccc)}\\ &\color{blue}{+(aa\ bbb\ cccc)}\tag{1} \end{align*}

We calculate the wanted number by writing the multinomial coefficients in the same order as the cases in (1). We obtain \begin{align*} &\binom{9}{2,3,4}-\binom{8}{1,3,4}-\binom{8}{2,1,1,4}-\binom{8}{2,3,1,2}\\ &\qquad+\binom{7}{1,1,1,4}+\binom{7}{1,3,1,2}+\binom{7}{2,1,4}+\binom{7}{2,1,1,1,2}\\ &\qquad\qquad+\binom{7}{2,3,1,1}+\binom{7}{2,3,2}\\ &\qquad-\binom{6}{1,1,4}-\binom{6}{1,1,1,1,2}-\binom{6}{1,3,1,1}-\binom{6}{1,3,2}\\ &\qquad\qquad-\binom{6}{2,1,1,2}-\binom{6}{2,1,1,1,1}-\binom{6}{2,1,1,2}-\binom{6}{2,3,1}\\ &\qquad+\binom{5}{1,1,1,2}+\binom{5}{1,1,1,1,1}+\binom{5}{1,1,1,2}+\binom{5}{1,3,1}\\ &\qquad\qquad+\binom{5}{2,1,1,1}+\binom{5}{2,1,2}+\binom{5}{2,1,1,1}\\ &\qquad-\binom{4}{1,1,1,1}-\binom{4}{1,1,2}-\binom{4}{1,1,1,1}-\binom{4}{2,1,1}\\ &\qquad+\binom{3}{1,1,1}\\ &\quad=1\,260-280-840-1\,680\\ &\qquad+210+420+105+1\,260+420+210\\ &\qquad-30-360-120-60-180-360-180-60\\ &\qquad+60+120+60+20+60+30+60\\ &\qquad-24-12-24-12\\ &\qquad+6\\ &\quad=1\,260-2\,800+2\,625-1\,350+410-72+6\\ &\,\,\quad\color{blue}{=79} \end{align*} in accordance with other answers.

Markus Scheuer
  • 108,315