# Words With 2 N

How many type of words through \$2n\$ letters deserve to be produced if I have an alphabet with \$n\$ letters and each of the letters need to happen precisely twice in the word, however no 2 consecutive letters are equal?

Thanks!  There is no easy closed formula for this (I think no recognized closed formula at all), but one deserve to provide a formula as a amount by making use of inclusion-exclusion.

You watching: Words with 2 n

First think about such orderings wright here the pairs of similar letters are distinguishable. Then \$displaystyle sum_k=0^n (-1)^k2^k(2n-k)!inomnk\$ provides the variety of such such orderings by inclusion-exemption (tbelow are \$(2n-k)!\$ ways for \$k\$ given pairs to be together (by merging the those pairs right into single elements) and the remainder arbitrarily ordered, \$2^k\$ ways to order within those offered pairs, and \$inomnk\$ methods to pick those \$k\$ pairs). By splitting by \$2^n\$ to remove the ordering of pairs of the same facets we can obtain the formula \$displaystyle frac12^nsum_k=0^n (-1)^k2^k(2n-k)!inomnk\$.

Share
Cite
Follow
answered Nov 25 "13 at 12:52 universalsetuniversalset
\$endgroup\$
1
\$egingroup\$
As mentioned in the comments, this sequence appears in the OEIS (A114938), and is a unique situation of an extra general result discovered somewhere else on this site (e.g., right here and here).

The OEIS gives the outcome as a sum:\$\$A_n=sum_k=0^nfrac(-1)^n-k(n+k)!2^knchoosek\=frac12^nsum_k=0^n(-2)^k(2n-k)!nchoosek,\$\$where the second variation is acquired from the initially by changing \$k ightarrow n-k\$ in the summation. To derive this from the even more general expression, we write\$\$A_n=int_0^infty (q_2(x))^n , exp(-x),dx,\$\$wbelow \$\$q_2(x) = sum_i=1^2 frac(-1)^2-ii! 2-1 choose i-1x^i=frac12x(x-2);\$\$so\$\$A_n=frac12^nint_0^inftyx^n(x-2)^ne^-xdx=frac12^nsum_k=0^n(-2)^knchoosekint_0^inftyx^2n-ke^-xdx,\$\$wbelow the binomial growth was used to \$(-2+x)^n\$. Because one can conveniently examine that \$int_0^inftyx^a e^-xdx=a!\$ (by repetitive integration by parts, for instance), the two expressions coincide.

Share
Cite
Follow
edited Apr 13 "17 at 12:21 Community♦
1
answered Nov 25 "13 at 16:27 mjqxxxxmjqxxxx
\$endgroup\$