Sub topic 10
Splitting items into unlabeled groups
This chapter assumes you can compute combinations with C(n, k), use the multiplication principle, and read factorial expressions. It builds on the combinations and identical-items chapters. The new skill is deciding when a count has to be divided because groups are interchangeable.
Labeled groups and unlabeled groups
A grouping problem asks you to split a set of distinct items into several groups. The key question is whether the groups can be told apart.
- Labeled groups have names or roles. Examples: "Team Red, Team Blue, Team Green", or "one person to each of three different offices".
- Unlabeled groups are interchangeable. Examples: "split 6 students into 3 pairs", or "divide 10 people into two teams of 5". Only the membership of each group matters.
Labeled groups are easy to count with the multiplication principle. Choose the members of the first group, then the second, and so on. Unlabeled groups need one extra step: remove the repeats caused by swapping interchangeable groups.
Counting labeled groups first
Split 6 people into three labeled teams (Red, Blue, Green) of 2 people each.
- Choose Red's 2 people from 6: C(6, 2) = 15.
- Choose Blue's 2 from the remaining 4: C(4, 2) = 6.
- Green gets the last 2: C(2, 2) = 1.
By the multiplication principle, the total is 15 × 6 × 1 = 90. This is the number of ways to fill three named slots.
Dividing out the repeats for unlabeled groups
Now remove the names. Take one split, for example {A, B}, {C, D}, {E, F}. In the labeled count, this one split appears once for every way to assign the three pairs to Red, Blue, and Green. That is 3! = 6 ways.
So the labeled count of 90 counts every unlabeled split exactly 6 times:
90 ÷ 3! = 15
This gives the general rule for splitting into equal-size groups. Splitting n items into m unlabeled groups that all have the same size k, where n = m·k, can be done in:
n! ÷ ((k!)^m × m!)
The (k!)^m part removes the ordering inside each group. The m! part removes the ordering of the groups themselves. For the example, 6! ÷ ((2!)^3 × 3!) = 720 ÷ (8 × 6) = 15, which matches.
import math
def equal_groups(n, size):
"""Ways to split n distinct items into unlabeled groups of equal size."""
m = n // size
ordered = 1
left = n
for _ in range(m):
ordered *= math.comb(left, size) # choose one group's members
left -= size
return ordered // math.factorial(m) # divide by m! to forget group order
print(equal_groups(6, 2)) # 15
print(equal_groups(9, 3)) # 280
print(equal_groups(10, 5)) # 126You can confirm the 15 by brute force. This code builds every ordering of 6 people, cuts each into consecutive pairs, and keeps only the distinct sets of pairs.
from itertools import permutations
seen = set()
for p in permutations(range(6)):
groups = frozenset(frozenset(p[i:i + 2]) for i in range(0, 6, 2))
seen.add(groups)
print(len(seen)) # 15The 720 orderings collapse to 15 distinct splits. Each split is produced by 48 orderings, which is 2!^3 × 3! = 8 × 6.
When group sizes differ, do not divide by m!
The division by m! exists only because swapping two groups of the same size gives the same split. If two groups have different sizes, they can never be swapped, so they are already distinguishable.
Split 8 people into a group of 3 and a group of 5. Choose the 3-person group in C(8, 3) = 56 ways. The other 5 people form the second group automatically. The answer is 56, with no division. The sizes act as labels.
Compare that with splitting 8 people into two groups of 4. Choosing one group of 4 gives C(8, 4) = 70. Each split is counted twice, once from each side, so the answer is 70 ÷ 2 = 35.
| Situation | Count | Reason |
|---|---|---|
| 8 people into groups of 3 and 5 | C(8, 3) = 56 | Sizes differ, so no swap is possible |
| 8 people into two groups of 4 | C(8, 4) ÷ 2 = 35 | Two equal groups can swap |
| 6 people into three pairs | 90 ÷ 3! = 15 | Three equal groups can swap |
| 6 people into Red, Blue, Green pairs | 90 | Labels prevent swaps |
Mixed sizes: divide only for the repeated sizes
Many problems have some groups of equal size and some not. Divide by the factorial of how many groups share each size.
Split 8 people into groups of sizes 2, 2, and 4.
- Choose the first pair: C(8, 2) = 28.
- Choose the second pair from the remaining 6: C(6, 2) = 15.
- The last 4 form the group of 4: C(4, 4) = 1.
The ordered count is 28 × 15 × 1 = 420. The two pairs are interchangeable, but the group of 4 is not. So divide by 2!:
420 ÷ 2 = 210
Here is a second case. Split 7 people into groups of 3, 2, and 2. The ordered count is C(7, 3) × C(4, 2) × C(2, 2) = 35 × 6 × 1 = 210. The two groups of 2 are interchangeable, so the answer is 210 ÷ 2 = 105.
You can write this as n! ÷ (product of each group size factorial × product of the factorials of how many groups share each size). For 7 people in groups of 3, 2, 2: 7! ÷ (3! × 2! × 2! × 2!) = 5040 ÷ 48 = 105. The last 2! is the swap of the two equal pairs.
import math
# 7 people into groups of sizes 3, 2, 2 (unlabeled)
ordered = math.comb(7, 3) * math.comb(4, 2) * math.comb(2, 2) # 210
print(ordered // math.factorial(2)) # 105: the two groups of 2 can swap
# Same answer from the factorial formula
print(math.factorial(7) // (math.factorial(3) * math.factorial(2) ** 2 * math.factorial(2))) # 105A decision flow for grouping problems
Checking an answer by a different route
Grouping answers are easy to inflate by a factor of m!, so a quick check is worth the time. Two checks work well.
- Count small cases by hand. Splitting 4 people into two pairs gives 3 splits: AB|CD, AC|BD, AD|BC. The formula gives C(4, 2) ÷ 2! = 6 ÷ 2 = 3. It matches.
- Add up cases. Split 4 people into two non-empty unlabeled groups of any size. The sizes can be 2 and 2, which gives 3 splits. They can also be 1 and 3, which gives C(4, 1) = 4 splits, and there is no division because the sizes differ. The total is 3 + 4 = 7. A shortcut agrees: each of the 4 people is in group 1 or group 2, which gives 2^4 = 16 assignments. Remove the 2 assignments with an empty group to get 14, then divide by 2 for the swap of group names to get 7.
Common errors
- Dividing when sizes differ. In a 3-and-5 split, nothing can be swapped, so any division is wrong.
- Forgetting to divide when sizes match. "Two teams of 5" counted as C(10, 5) = 252 is double the correct 126.
- Dividing by the wrong factorial. For sizes 2, 2, 4, divide by 2! (two equal groups), not by 3! (three groups in total).
- Treating hidden labels as absent. If the problem says the groups go to different rooms, projects, or days, they are labeled. Do not divide.
- Dividing twice. If you used a formula that already includes the m! term, do not divide by m! again.
Connection to what comes next
Counting unlabeled groups sets up the probability chapter. A probability such as "what is the chance that two specific friends end up in the same pair?" needs the count of all unlabeled splits as its denominator. If you count that denominator as the labeled 90 instead of the unlabeled 15, you must also count the numerator in the labeled way. Use the same convention for both. The ratio then comes out the same.
Exercises
Exercise
A teacher splits 8 students into 4 unlabeled pairs for a project. In how many ways can this be done?
Show answer
Choose pairs in order: C(8, 2) × C(6, 2) × C(4, 2) × C(2, 2) = 28 × 15 × 6 × 1 = 2520. The 4 pairs are interchangeable, so divide by 4! = 24. The answer is 2520 ÷ 24 = 105. The formula gives the same value: 8! ÷ ((2!)^4 × 4!) = 40320 ÷ (16 × 24) = 105.
Exercise
A manager divides 9 employees into three groups of 3. Case 1: the groups go to three different named projects. Case 2: the groups are not assigned to anything and are not named. Find the count for each case.
Show answer
Case 1 (labeled): C(9, 3) × C(6, 3) × C(3, 3) = 84 × 20 × 1 = 1680. Case 2 (unlabeled): the three groups have equal size and can be swapped, so divide by 3! = 6. The answer is 1680 ÷ 6 = 280.
Exercise
In how many ways can 10 distinct books be split into one pile of 4, one pile of 3, and two piles of 2, if the piles are not labeled?
Show answer
The ordered count is C(10, 4) × C(6, 3) × C(3, 2) × C(1, 2)... this fails, because only 3 books remain after the pile of 4 and the pile of 3 are chosen from 10 and 6, and 4 + 3 + 2 + 2 = 11. The sizes do not add up to 10, so the split described is impossible and the count is 0. For a valid version, use piles of 4, 2, 2, 2: 10! ÷ (4! × 2! × 2! × 2! × 3!) = 3628800 ÷ (24 × 8 × 6) = 3628800 ÷ 1152 = 3150.
Exercise
Ten people split into two unlabeled teams of 5. Two specific people, Ana and Ben, are among the ten. How many of the splits put Ana and Ben on the same team?
Show answer
Put Ana and Ben together. The other 3 members of their team come from the remaining 8 people: C(8, 3) = 56. The other 5 people form the second team automatically. Because Ana's team is identified by containing Ana, there is no swap to remove. The answer is 56. As a check, the total number of splits is 252 ÷ 2 = 126, and the splits with Ana and Ben apart number 126 − 56 = 70. Counting those directly also gives C(8, 4) = 70 (choose Ana's 4 teammates from the 8 others, excluding Ben), and 56 + 70 = 126.