8

How many words with $2n$ letters can be created if I have an alphabet with $n$ letters and each of the letters have to occur exactly twice in the word, but no two consecutive letters are equal?

Thanks!

Lord_Farin
  • 17,743
  • Put $R=n$ and $S=2$ in my answer here: http://math.stackexchange.com/questions/430000/how-many-arrangements-of-a-generalized-deck-of-generalised-cards-have-pairs/448411#448411 –  Nov 25 '13 at 13:12
  • See also http://oeis.org/A114938 –  Nov 25 '13 at 13:16

5 Answers5

1

There is no simple closed formula for this (I think no known closed formula at all), but one can give a formula as a sum by using inclusion-exclusion.

First consider such orderings where the pairs of identical letters are distinguishable. Then $\displaystyle \sum_{k=0}^n (-1)^k2^k(2n-k)!\binom{n}{k}$ gives the number of such such orderings by inclusion-exclusion (there are $(2n-k)!$ ways for $k$ given pairs to be together (by merging the those pairs into single elements) and the rest arbitrarily ordered, $2^k$ ways to order within those given pairs, and $\binom{n}{k}$ ways to pick those $k$ pairs). By dividing by $2^n$ to eliminate the ordering of pairs of identical elements we can obtain the formula $\displaystyle \frac{1}{2^n}\sum_{k=0}^n (-1)^k2^k(2n-k)!\binom{n}{k}$.

universalset
  • 8,269
  • 20
  • 33
1

As pointed out in the comments, this sequence appears in the OEIS (A114938), and is a special case of a more general result found elsewhere on this site (e.g., here and here).

The OEIS gives the result as a sum: $$ A_{n}=\sum_{k=0}^{n}\frac{(-1)^{n-k}(n+k)!}{2^k}{{n}\choose{k}}\\=\frac{1}{2^n}\sum_{k=0}^{n}(-2)^k(2n-k)!{{n}\choose{k}}, $$ where the second version is obtained from the first by changing $k\rightarrow n-k$ in the summation. To derive this from the more general expression, we write $$A_{n}=\int_0^\infty (q_2(x))^n \, \exp(-x)\,dx,$$ where $$q_2(x) = \sum_{i=1}^{2} \frac{(-1)^{2-i}}{i!} {2-1 \choose i-1}x^i=\frac{1}{2}x(x-2);$$ so $$ A_n=\frac{1}{2^n}\int_{0}^{\infty}x^n(x-2)^ne^{-x}dx=\frac{1}{2^n}\sum_{k=0}^{n}(-2)^k{{n}\choose{k}}\int_{0}^{\infty}x^{2n-k}e^{-x}dx, $$ where the binomial expansion was applied to $(-2+x)^n$. Since one can readily check that $\int_{0}^{\infty}x^a e^{-x}dx=a!$ (by repeated integration by parts, for instance), the two expressions coincide.

mjqxxxx
  • 41,358
0

My answer is similar to suraj's, however, I will explain a few nuances below:

${(2n-r)!}$ : in the numerators are derived from remove two of the same letters, and adding them back into the sequence as one combined letter. The arrangements of these combined letters (among themselves) do not matter because they are the same.

$\binom{n}{r}$ : is representative of how many letter pairs we are assuming will be together.

answer = $\frac{(2n)!}{2!^{n}} - \binom{n}{1}\frac{(2n-1)!}{(2!)^{n-1}}\ \ \ + ... + \ \ (-1)^{r}\binom{n}{r}\frac{(2n-r)!}{(2!)^{n-r}}\ \ \ \ \ +...+ \ \ (-1)^{n}\binom{n}{n}\frac{(2n-n)!}{(2!)^{n-n}}$

I have programmed this in python, and have tested that $n = 3$ returns 30. Below is the pasted code in python:

import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

def compute(n):
    total = math.factorial(2*n)/(2**n)
    sum = 0
    for i in range(1,n+1):
        choice = nCr(n,i)
        sign = (-1)**i
        numerator = math.factorial(2*n - i)
        denominator = 2**(n-i)
        sum += choice * sign * (numerator/denominator)
    return total + sum

print(compute(3))
0

We have 2n positions to fill, lets fill two positions with one letter.

We have n pairs of double letters. For the first pair of double letters we have (2n-2)(2n-3) possible positions. This is because first we put the letter on a position not on the sides, and the other letter on the remaining positions that are not next to our letter.

[edit] Now we proceed for the next letter: We have 2n-2 positions left to fill with another letter, use the above procedure.

Keep doing this, in total n times, to get all words. It works because it doesnt matter where we place one letter (and his double) for the other letters.

[EDIT] I have forgotten one thing:The words of the form a _ _ _ a. Adding them we get: For n to 0 get the product of: (2n-2)(2n-3) And add to this :

n times 'For n-1 to 2 get the product of: (2n-2)(2n-3) '

This gives for n=3 : 30 words.

For n=4 : 840

Ryan
  • 166
  • I don't know what method you intended by this, but I'm pretty sure it doesn't work. Mostly because it's not so easy to reduce to smaller cases: the number of ways one can place the $k$-th letter depends on how one places the first $k-1$ letters. – universalset Nov 25 '13 at 13:04
  • see my solution. – Suraj M S Nov 25 '13 at 13:20
  • First letter we place via the above method. Then for the next letter we have 2n-2 positions to fill, via the above method. We keep going like this until we used all n letters. This should give all the possibilities.

    Ill edit the post for more clarity.

    – Ryan Nov 25 '13 at 14:49
  • @universalset Yes, if you try to place letters one by one. But I dont do that, I place the double letters immediatly. – Ryan Nov 25 '13 at 14:57
  • But the number of ways for you to place the pair of 'c's depends on how exactly you placed your 'a's and 'b's. (E.G.: AB__AB gives no ways; AB_AB_ gives one). How would you use your method to compute the answer for $n=4$? – universalset Nov 25 '13 at 15:02
  • I did forget the words of the form a _ _ _ a. To add these combinations: First do as normal. Then add the combinations for (n-1) letters! – Ryan Nov 25 '13 at 16:06
  • The answer for $n=4$ is in fact 864. I suggest you look at the other answers. – universalset Nov 25 '13 at 16:32
0

first of all if you want to find the number of words in which no two same letters are equal then it is equivalent to finding the total number of words that can be made with the letters minus the number of words in which consecutive letters are present.

you can easily find the total words that can be made with the letters to be $$\frac{2n!}{(2!)^n}$$ now to find the no. of words that in which letters are consecutive.

initially consider a pair $xx$ is formed in the word with no other same elements consecutive. Consider the set $xx$ as a single element which is free to traverse to any position between the remaining $2n-2$ elements.

then the set $xx$ can be placed in any of the available $2n-1$ positions. At the same time the remaining $2n-2$ elements can itself be rearranged $\frac{(2n-2)!}{(2!)^{n-1}}$

therefore the total no. of ways a pair of letters can become consecutive is $$\frac{(2n-2)!*(2n-1)}{(2!)^{n-1}}$$ $$= \frac{(2n-1)!}{(2!)^{n-1}}$$ now extend this for more number of sets from $1$ to $n$.

you will find the final answer for as $k$ runs from $1$ $\to$ $n$ is $$ \frac{2n!}{(2!)^n}-\sum \frac{(2n-k)!}{(2!)^{n-k}}$$

Suraj M S
  • 1,891