Sub topic 7
Arrangements with Repeated Letters and Identical Objects
This chapter assumes you can compute factorials, apply the multiplication principle, and use permutations when order matters. You should also be able to treat a group of items as one block, which the restrictions chapter covers in more detail. Here you learn what changes when some of the objects being arranged are indistinguishable.
Why the Basic Formula Overcounts
Arranging n distinct objects in a row gives n! orders. If some objects are identical, many of those orders look the same.
Take the word BANANA. Mark the three A's as A1, A2, A3 and the two N's as N1, N2, so every letter is distinct. There are 6! = 720 arrangements. The visible word "ANANAB" appears many times in that list, because swapping A1, A2, A3 among themselves gives 3! = 6 versions, and swapping N1, N2 gives 2! = 2 versions. Each visible word is counted 6 × 2 = 12 times.
Dividing removes the repeats:
6! / (3! × 2!) = 720 / 12 = 60
The General Rule
Suppose n objects include p identical objects of one kind, q of a second kind, r of a third kind, and the rest are all different. The number of distinct arrangements is:
n! / (p! × q! × r! × ...)
Letters that appear once contribute 1! = 1, so you can leave them out of the denominator.
from collections import Counter
from itertools import permutations
from math import factorial
def arrangements(word):
# n! divided by the factorial of each letter's count
result = factorial(len(word))
for count in Counter(word).values():
result //= factorial(count)
return result
for w in ["BANANA", "LEADER"]:
brute = len(set(permutations(w))) # brute-force check on small words
print(w, arrangements(w), brute)
print(arrangements("MISSISSIPPI")) # 34650The output is BANANA 60 60, LEADER 360 360, and 34650. The brute-force check agrees with the formula on the small words.
Worked examples
- MISSISSIPPI. There are 11 letters: 1 M, 4 I, 4 S, 2 P. The count is 11! / (4! × 4! × 2!) = 34650.
- ALLAHABAD. There are 9 letters: A appears 4 times, L twice, and H, B, D once each. The count is 9! / (4! × 2!) = 362880 / 48 = 7560.
- LEADER. E appears twice, so the count is 6! / 2! = 360.
Identical Objects Beyond Letters
The same formula applies to any objects that cannot be told apart. These are common CAT setups:
- Colored balls. Arranging 4 red, 3 blue and 2 green balls in a row gives 9! / (4! × 3! × 2!) = 1260.
- Grid paths. To go from the bottom-left to the top-right of a grid that is 4 units wide and 3 units tall, using only right (R) and up (U) moves, you need 4 R's and 3 U's in some order. The count is 7! / (4! × 3!) = 35. This equals 7C3, because choosing which 3 of the 7 steps are U's fixes the whole path.
- Binary strings. The number of 8-digit strings with exactly 3 ones is 8! / (3! × 5!) = 8C3 = 56.
With only two kinds of object, the formula n! / (p! × q!) is the same as nCp. The multinomial formula is the general case of the combination formula.
Repeated Letters with Restrictions
Restrictions combine with the division rule. The method is to apply the restriction first, so that you have a new set of objects, and then divide for the repeats in that new set.
Letters together
How many arrangements of MISSISSIPPI keep all four S's together?
- Glue the four S's into one block, which counts as a single object.
- The objects are now M, four I's, the block, and two P's, which is 1 + 4 + 1 + 2 = 8 objects.
- The count is 8! / (4! × 2!) = 40320 / 48 = 840.
Inside the block all four S's are identical, so the block has only one internal order. No extra factor is needed.
Vowels together with a repeated vowel
How many arrangements of LEADER keep all vowels together? The vowels are E, A, E.
- Inside the block, the vowels can be ordered in 3! / 2! = 3 ways.
- The block plus the consonants L, D, R gives 4 distinct objects, which can be arranged in 4! = 24 ways.
- The total is 24 × 3 = 72.
Letters apart
To keep identical letters apart, arrange the other letters first, then place the identical letters in the gaps. For BANANA with no two A's adjacent, the three non-A letters B, N, N can be arranged in 3! / 2! = 3 ways. They create 4 gaps (one before, two between, one after). Choose 3 of the 4 gaps for the A's: 4C3 = 4. The total is 3 × 4 = 12.
Selecting and Then Arranging
Some questions ask how many words of a given length can be formed from letters that include repeats. You cannot use a single formula here. Split the problem into cases by the pattern of repeated letters, count each case, and add the cases (addition principle).
Example: how many 3-letter arrangements can be made from the letters of AABBC?
| Pattern | Letter choices | Arrangements each | Total |
|---|---|---|---|
| All different (A, B, C) | 1 | 3! = 6 | 6 |
| Two A's plus one other (B or C) | 2 | 3! / 2! = 3 | 6 |
| Two B's plus one other (A or C) | 2 | 3! / 2! = 3 | 6 |
The total is 6 + 6 + 6 = 18. You can check it by computer:
from itertools import permutations
print(len(set(permutations("AABBC", 3)))) # 18A pattern of three identical letters is impossible here because no letter appears three times. Check each case against the available supply of every letter.
Common Errors
- Dividing by the wrong factorials. Divide by the factorial of how many times each letter appears, not by the factorial of the number of distinct letters.
- Forgetting that blocks can have repeats. A block of vowels is itself an arrangement of objects, some of which may be identical.
- Treating identical objects as distinct. A question about 5 identical balls differs from one about 5 numbered balls. Read the wording for "identical", "alike" or "of the same kind".
- Applying the full formula to partial selections. If you use fewer letters than the word has, the full-word formula does not apply. Use the case split above.
- Counting 0! incorrectly. If a letter has count 0 in a case, 0! = 1, so it has no effect.
Exercise
How many distinct arrangements are there of the letters of the word COMMITTEE?
Show answer
COMMITTEE has 9 letters: C, O, M twice, I, T twice, E twice. The count is 9! / (2! × 2! × 2!) = 362880 / 8 = 45360.
Exercise
In how many arrangements of the letters of ALLAHABAD do the two L's sit next to each other?
Show answer
Glue the two L's into one block. The objects are now 8: A four times, the block L L, H, B, D. The count is 8! / 4! = 40320 / 24 = 1680.
Exercise
A path goes from the bottom-left corner to the top-right corner of a grid that is 5 units wide and 4 units tall, using only right and up moves. How many paths are there, and how many of them pass through the point 2 units right and 2 units up from the start?
Show answer
A path has 5 R's and 4 U's, so there are 9! / (5! × 4!) = 126 paths. To pass through (2, 2), count the paths from the start to (2, 2), which is 4! / (2! × 2!) = 6, and multiply by the paths from (2, 2) to (5, 4). That second part needs 3 R's and 2 U's, which gives 5! / (3! × 2!) = 10. The total is 6 × 10 = 60.