How many permutations are possible of $n_1$ a's, $n_2$ b's, and $n_3$ c's, such that no two a's and no two b's are adjacent?

115 Views Asked by At

Given $n_1$ number of a's, $n_2$ number of b's, $n_3$ number of c's.

They form a sequence using all these characters such that no two a's and no two b's are adjacent.

(a and b can be adjacent, but two a's or b's cannot be adjacent. c has no restrictions.)

for example : acbccab is valid for $n_1=2$, $n_2=2$, $n_3=3$

but,

cbcbcaa is not valid as two a's are adjacent.

I have tries lot of things but nothing worked.

Can somebody tell me how to solve this problem?

2

There are 2 best solutions below

0
On

I would define coupled recurrences. Let $A(x,y,z)$ be the number of strings $x\ a$s, $y\ b$s, and $z\ c$s that ends in $a$ and similarly for $B$ and $C$. Then $$A(x,y,z)=B(x-1,y,z)+C(x-1,y,z)$$ and similar for $B$. The recurrence for $C$ is slightly different. A recursive computer program will make it easy. There might be a generating function approach.

2
On

This answer is based upon generating functions of Smirnov words. These are words with no equal consecutive characters. (See example III.24 Smirnov words from Analytic Combinatorics by Philippe Flajolet and Robert Sedgewick for more information.)

We have $n_1$ $a$'s, $n_2$ $b$'s and $n_3$ $c$'s and are looking for Smirnov words of length $n_1+n_2+n_3$.

A generating function for the number of Smirnov words over the three letter alphabet $V=\{a,b,c\}$ is given by \begin{align*} \left(1-\frac{a}{1+a}-\frac{b}{1+b}-\frac{c}{1+c}\right)^{-1}\tag{1} \end{align*}

In fact there is no restriction given for the character $c$. We respect this by substituting \begin{align*} c\to c+c^2+c^3+\cdots=\frac{c}{1-c} \end{align*}

We so obtain from (1) the generating function \begin{align*} \left(1-\frac{a}{1+a}-\frac{b}{1+b}-\frac{\frac{c}{1-c}}{1+\frac{c}{1-c}}\right)^{-1} =\color{blue}{\frac{(1+a)(1+b)}{1-c-ab-ac-bc-abc}}\tag{2} \end{align*}

We use the coefficient of operator $[z^n]$ to denote the coefficient of $z^n$ in a series $A(z)$.

The number of wanted words of length $n_1+n_2+n_3$ is therefore \begin{align*} \left[a^{n_1}b^{n_2}c^{n_3}\right]&\left(1-\frac{a}{1+a}-\frac{b}{1+b}-\frac{\frac{c}{1+c}}{1+\frac{c}{1+c}}\right)^{-1}\\ &\color{blue}{=\left[a^{n_1}b^{n_2}c^{n_3}\right]\frac{(1+a)(1+b)}{1-c-ab-ac-bc-abc}}\tag{3} \end{align*}

Example:

We consider the example of OP setting $(n_1,n_2,n_3)=(2,2,3)$ and we obtain from (3) with some help of Wolfram Alpha \begin{align*} \left[a^2b^2c^3\right]\frac{(1+a)(1+b)}{1-c-ab-ac-bc-abc}\color{blue}{=110} \end{align*}

The $110$ valid words are listed below with OPs stated word marked in $\color{blue}{\text{blue}}$.

\begin{array}{cccccc} \mathrm{ababccc}&\mathrm{acbacbc}&\mathrm{bacaccb}&\mathrm{bcbacca}&\mathrm{cacbcab}&\mathrm{ccabcab}\\ \mathrm{abacbcc}&\mathrm{acbaccb}&\mathrm{bacbacc}&\mathrm{bcbcaca}&\mathrm{cacbcba}&\mathrm{ccabcba}\\ \mathrm{abaccbc}&\mathrm{acbcabc}&\mathrm{bacbcac}&\mathrm{bccabac}&\mathrm{caccbab}&\mathrm{ccacbab}\\ \mathrm{abacccb}&\mathrm{acbcacb}&\mathrm{bacbcca}&\mathrm{bccabca}&\mathrm{cbabacc}&\mathrm{ccbabac}\\ \mathrm{abcabcc}&\mathrm{acbcbac}&\mathrm{baccabc}&\mathrm{bccacab}&\mathrm{cbabcac}&\mathrm{ccbabca}\\ \mathrm{abcacbc}&\mathrm{acbcbca}&\mathrm{baccacb}&\mathrm{bccacba}&\mathrm{cbabcca}&\mathrm{ccbacab}\\ \mathrm{abcaccb}&\color{blue}{\mathrm{acbccab}}&\mathrm{baccbac}&\mathrm{bccbaca}&\mathrm{cbacabc}&\mathrm{ccbacba}\\ \mathrm{abcbacc}&\mathrm{acbccba}&\mathrm{baccbca}&\mathrm{bcccaba}&\mathrm{cbacacb}&\mathrm{ccbcaba}\\ \mathrm{abcbcac}&\mathrm{accabcb}&\mathrm{bacccab}&\mathrm{cababcc}&\mathrm{cbacbac}&\mathrm{cccabab}\\ \mathrm{abcbcca}&\mathrm{accbabc}&\mathrm{bacccba}&\mathrm{cabacbc}&\mathrm{cbacbca}&\mathrm{cccbaba}\\ \mathrm{abccabc}&\mathrm{accbacb}&\mathrm{bcabacc}&\mathrm{cabaccb}&\mathrm{cbaccab}&\\ \mathrm{abccacb}&\mathrm{accbcab}&\mathrm{bcabcac}&\mathrm{cabcabc}&\mathrm{cbaccba}&\\ \mathrm{abccbac}&\mathrm{accbcba}&\mathrm{bcabcca}&\mathrm{cabcacb}&\mathrm{cbcabac}&\\ \mathrm{abccbca}&\mathrm{acccbab}&\mathrm{bcacabc}&\mathrm{cabcbac}&\mathrm{cbcabca}&\\ \mathrm{acbcabc}&\mathrm{babaccc}&\mathrm{bcacacb}&\mathrm{cabcbca}&\mathrm{cbcacab}&\\ \mathrm{acbcacb}&\mathrm{babcacc}&\mathrm{bcacbac}&\mathrm{cabccab}&\mathrm{cbcacba}&\\ \mathrm{acabcbc}&\mathrm{babccac}&\mathrm{bcacbca}&\mathrm{cabccba}&\mathrm{cbcbaca}&\\ \mathrm{acabccb}&\mathrm{babccca}&\mathrm{bcaccab}&\mathrm{cacabcb}&\mathrm{cbccaba}&\\ \mathrm{acacbcb}&\mathrm{bacabcc}&\mathrm{bcaccba}&\mathrm{cacbabc}&\mathrm{ccababc}&\\ \mathrm{acbabcc}&\mathrm{bacacbc}&\mathrm{bcbacac}&\mathrm{cacbacb}&\mathrm{ccabacb}&\\ \end{array}