In this exercise, we will explore how to enumerate elements of a multiset (a set that contains elements that are not necessarily distinct). Consider the problem of having to determine the number of permutations of the letters in the word CODE. From previous exercises, we know the number of permutations is 4!. What about the word CODEC? Claiming the answer is 5!, as you did for the word CODE, would be incorrect. This is because the letter C appears more than once. If we write the word like this C1ODEC2, the following permutation of the word exists: C2ODEC1 which is the same as the original word. Since both C’s are identical, it is irrelevant which one is in which position. Therefore we must scale the number of permutations down. To do this, we consider that the order of the two C’s, in whichever spot they appear, does not matter. Sounds familiar? That’s right, we scale down by 2!. So the number of permutations of the word CODEC is:
If we were permuting a word with more than one repeated character, we would further scale down the permutations by the count of the other repeated letters. Generally speaking, the number of permutations of a multiset is:
Where n is the total size of the multiset and each of rk‘s represents the count of each element.
Another way of computing this is to “choose” a spot for each element. Consider the word GOOGLE, how many permutations of this word can we have? We “choose” two spots for the G’s, “and” we “choose” two of the remaining spots for the O’s, “and” we “choose” one remaining spot each for the L and the E:
If the repeated letters can be treated as distinct, how many permutations are there for the word COMBINATORICS? Store your answer in the
Can you correct the previous calculation to find the actual number of permutations of the word COMBINATORICS? Store your answer in the
Can you find the number of permutations for the word COMBINATORICS by using the formula for combination? Store your answer in the
permutation_3 variable. Use the result to verify your answer to the previous question.
Remember the following identities: