patternMinor
Finding the number of distinct permutations of length N with n different symbols
Viewed 0 times
distinctnumberthewithlengthsymbolsdifferentfindingpermutations
Problem
I have one puzzle whose answer I have boiled down to finding the total number and which type of permutation they are.
For example if the string is of length ten as $w = aabbbaabba$, the total number of permutations will be
$\qquad \displaystyle \frac{|w|}{|w|_a! \cdot |w|_b!} = \frac{10!}{5!\cdot 5!}$
Now had the string been of distinct characters, say $w'=abcdefghij$, I would have found the permutations by this algorithm :
Can some one throw new ideas on this - how to find the number of permutations for a string having repeated characters? Is there any other mathematical/scientific name of for what I am trying to do?
For example if the string is of length ten as $w = aabbbaabba$, the total number of permutations will be
$\qquad \displaystyle \frac{|w|}{|w|_a! \cdot |w|_b!} = \frac{10!}{5!\cdot 5!}$
Now had the string been of distinct characters, say $w'=abcdefghij$, I would have found the permutations by this algorithm :
for i = 1 to |w|
w = rotate(w)
w = rotate(w)
return w.head + rotate(w.tail)Can some one throw new ideas on this - how to find the number of permutations for a string having repeated characters? Is there any other mathematical/scientific name of for what I am trying to do?
Solution
The total number of (different) permutations of strings with $n_i$ characters of type $i$ is given by
$$\frac{(\sum_i n_i)!}{\prod_i n_i!}.$$
In other words, if the length of the string is $n=n_1 + n_2 +...$, you have
$\frac{n!}{n_1!n_2!n_3!\ldots}$ different permutations.
Note that the formula fits your simple case.
Why is this formula correct?
Because $n!$ is the number of permutations. But some permutations give the same string (e.g.,
$$\frac{(\sum_i n_i)!}{\prod_i n_i!}.$$
In other words, if the length of the string is $n=n_1 + n_2 +...$, you have
$\frac{n!}{n_1!n_2!n_3!\ldots}$ different permutations.
Note that the formula fits your simple case.
Why is this formula correct?
Because $n!$ is the number of permutations. But some permutations give the same string (e.g.,
aa rotated is still aa). Then we need to "remove" all the permutations that give the same string. For a given string, for each letter $i$, there are $n_i$ permutations that are identical to the string we started with. So (for each possible letter $i$) we divide by this number to get the final result.Context
StackExchange Computer Science Q#2443, answer score: 6
Revisions (0)
No revisions yet.