Counting permutation of duplicate items

I am not really sure I fully understand the formula for finding the number of permutation of duplicate items.
The formula is:
$$\frac{n!}{p!q!r!\cdots}$$

Where do the factorials in the denominator exactly come from?

If we asssume the string "ANNA" and we want the count of the permutation of duplicate items.

We have $$4$$ characters so since we have $$4$$ options for the first character, $$3$$ for the second, $$2$$ for the third and $$1$$ for the last we have $$4!$$ different permutations.

But some of the characters are duplicates.
We have "A" and "N" repeated, meaning it adds more permutations to the outcome.
If $$p=2$$ is the number of occurences of "A" and if $$q = 2$$ is the number of occurences for "N" then would the $$p!$$ and $$q!$$ essentially be selecting $$1$$ item at a time from $$2$$ (or $$p$$) duplicates? So essentially are the denominators the binomial $$\binom{2}{1}$$ (or generally $$\binom{p}{1}$$ where $$p$$ are the number of repeated characters) where order does not matter?
Is my understanding correct?

A different way of viewing this formula which avoids "division by symmetry" arguments:

Given $$n$$ items, $$p$$ of which are identical of one type, $$q$$ of which are identical of another type, $$r$$ of which are identical of a third type, etc... with $$p+q+r+\dots = n$$, approach the count by following the steps:

Pick which of the spaces are used by the $$p$$ objects of the first type. There are $$\binom{n}{p}$$ ways to make this choice

Pick which of the remaining spaces are used by the $$q$$ objects of the second type. There are $$\binom{n-p}{q}$$ ways to make this choice given the earlier choice

Pick which of the remaining spaces are used by the $$r$$ objects of the third type. There are $$\binom{n-p-q}{r}$$ ways to make this choice given the earlier choices

$$\vdots$$

This gives a final total of:

$$\binom{n}{p}\binom{n-p}{q}\binom{n-p-q}{r}\cdots$$

Note, this explanation was able to completely avoid division as an operation as binomial coefficients could have been defined recursively purely using addition and multiplication.

Now... if you insist on rewriting this using fractions, you should know that $$\binom{a}{b}=\dfrac{a!}{b!(a-b)!}$$ in which case you have

$$\binom{n}{p}\binom{n-p}{q}\binom{n-p-q}{r}\cdots = \dfrac{n!}{p!\color{red}{(n-p)!}}\cdot \dfrac{\color{red}{(n-p)!}}{q!\color{blue}{(n-p-q)!}}\cdot\dfrac{\color{blue}{(n-p-q)!}}{r!(n-p-q-r)!}\cdots$$

Cancelling the numerators of each term after the first in the product with a portion of the denominator from the previous term gives the well known $$\dfrac{n!}{p!q!r!\cdots}$$

• Pick which of the spaces are used by the 𝑝 objects of the first type. the part that is confusing to me is that the number of spaces across the length of the string is not taken into account. I think that is the root of my confusion
– Jim
Commented Feb 24, 2021 at 16:58
• @Jim $n$ is the original length of the string and the original number of spaces. As spaces within the string start being filled, you have fewer spaces going forward... $n-p$ after $p$ spaces have been filled by objects of the first type, $n-p-q$ after filling objects of first and second type, etc... Commented Feb 24, 2021 at 17:00
• So at the first iteration, we have total of $\binom{n}{p}$ (where order does not matter) permutations of the $p$ characters but that also implies spaces ($n-p$) between the characters or also no spaces?
– Jim
Commented Feb 24, 2021 at 17:04
• There are $\binom{6}{3}\binom{3}{2}\binom{1}{1} =20\cdot 3\cdot 1 = \dfrac{6!}{3!2!1!} = 60$ ways of arranging the letters in the word BANANA Commented Feb 24, 2021 at 17:11
• I realize I did $\binom{3}{2}$ there in my last comment. I could just as easily have written this as $\binom{6}{3}\binom{3}{1}\binom{2}{2}$ instead. The point being, you should be able to convince yourself that you can fill in the spaces by your different types of letters in whatever order you wanted, be it alphabetical, in order of quantity, or however else... and the final resulting count should be the same. This is analogous to just rearranging the factorials in the denominator. Commented Feb 24, 2021 at 17:31

The first part giving $$4!=24$$ different permutations of $$4$$ distinct objects is fine.

Now we consider the word $$ANNA$$ where we have two letters of one kind $$A$$ and two letters of another kind $$N$$.

• Let $$x$$ denote the number of different permutations we can obtain from the letters $$A,A,N,N$$.

• Suppose the $$2$$ letters $$A$$ are replaced by $$2$$ new letters, distinct from each other and from all other letters being permuted. These $$2$$ new letters may be permuted in $$2!$$ ways; hence the number of permutations of the new set of objects is $$x\cdot 2!$$.

• Next suppse the $$2$$ letters $$N$$ are replaced by $$2$$ new letters, distinct from each other and from all other letters being permuted. These $$2$$ new letters may be permuted in $$2!$$ ways; hence the number of permutations of the new set of objects is $$x\cdot 2! \cdot 2!$$.

• Since the number of permutations of $$4$$ distinct letters is $$4!$$ we obtain \begin{align*} x\cdot 2!\cdot 2!&=4!\\ \color{blue}{x}&\color{blue}{=\frac{4!}{2!2!}} \end{align*}

Doing the same approach with $$p$$ equal objects of one kind, $$q$$ equal objects of another kind, and so on, we obtain in general \begin{align*} \frac{n!}{p!q!\cdots} \end{align*} with $$p+q+\cdots =n$$.

• Let 𝑥 denote the number of different permutations are these unique permutations?
– Jim
Commented Feb 24, 2021 at 22:21
• @Jim: $x$ denotes the number of all different permutations which are distinguishable. Commented Feb 24, 2021 at 22:32

$$n!$$ is, as you stated, the number of ways to permutate if no item is a duplicate. However, let's take ANNA as an example. Lets's number the letters by 1-4 according to their position ($$1=4=A$$, $$2=3=N$$) So, within the $$4!$$ options, we have, for example, 1324 and 1234 which are identical (both spell ANNA). The inner permutation between two identical items is what you see in the denominator; for this example, you have $$2!$$ since $$1=4$$, and $$2!$$ since $$2=3$$. So, all in all you get $$\frac {4!} {2!2!} = 24/4 = 6$$

• inner permutation between two identical items I don't understand what this statement means. Could you please elaborate or rephrase?
– Jim
Commented Feb 24, 2021 at 12:13
• 23 and 32 are two permutations in which the word becomes NN. There are "inner" permutations, allowing for a permutation (1234 1324 both spell ANNA) but with different Ns at different places. That is an inner permutation. Commented Feb 25, 2021 at 16:01

The denominators (p, q, r...) are permutations themselves. You mention C(p, 1) = p as the denominator which is not correct. The correct denominator is $$p!$$

A simpler way to understand this is: Let's take the string "ANNA". We have 4! (n! for n letters) permutations of this, ignoring repetitions. For each instance of these permutation, e.g., $$A_1 A_2 NN$$ and $$A_2 A_1 N N$$, where $$A_1$$ is the first A and so on. So the string $$AANN$$ is repeated twice (2!, in case of p repetitions of a letter it is p!), if we only take the duplicates due to the permutations of A. To discount the duplicates, you need to divide by p! If you follow the same line of logic, you get the formula you mentioned.

• So the string 𝐴𝐴𝑁𝑁 is repeated twice (2!,...) how do we go from repeated twice to $2!$? That is the question
– Jim
Commented Feb 24, 2021 at 12:12
• ignore NN and take the first two letters. "AA..". The number of permutations of this is 2!. Now if you have p of these in arbitrary positions $A_1 ... A_2 ... A_3... A_p$. Now treat each A as a distinct A. You have p! permutations of these, the same way you have n! permutations of a word with n letters. To explain the permutation formula, you have to imagine $p$ empty boxes, which need to be filled with p A's. For the first box, you have $p$ possibilities. For the second $p-1$, since you have used up a particular A. So total possibilities are $p (p-1) (p-2) ... 1 = p!$ Commented Feb 24, 2021 at 12:18
• So the number of permutation is not dependent on the number of invidual positions a character can be placed? E.g. if the string has length $n=12$ and repeated characters are $p=2$ then would it still be $2!$?
– Jim
Commented Feb 24, 2021 at 14:19
• That's correct. Commented Feb 25, 2021 at 15:21