6

What is an algorithm to partition $nk$ objects a total of $\frac{1}{n}\binom{nk}{k}$ times, each time making subsets of size exactly $k$, so that no subset of size $k$ is ever repeated?

For example, if $n=k=3$, then we have $9$ objects and we want to partition into groups of size $3$. We must hit all $\binom{9}{3}=84$ combinations in $\frac{1}{3}\binom{9}{3}=28$ partitions. For this example, the naive approach of iterating through all permutations in order and greedily choosing the first ones that work (as shown below) does not suffice; it can hit only $72$ of the $84$ combinations.

$[(0, 1, 2), (3, 4, 5), (6, 7, 8)], [(0, 1, 3), (2, 4, 6), (5, 7, 8)], [(0, 1, 4), (2, 3, 7), (5, 6, 8)], [(0, 1, 5), (2, 3, 6), (4, 7, 8)], [(0, 1, 6), (2, 3, 8), (4, 5, 7)], [(0, 1, 7), (2, 3, 5), (4, 6, 8)], [(0, 1, 8), (2, 3, 4), (5, 6, 7)], [(0, 2, 3), (1, 5, 8), (4, 6, 7)], [(0, 2, 4), (1, 5, 6), (3, 7, 8)], [(0, 2, 5), (1, 4, 7), (3, 6, 8)], [(0, 2, 6), (1, 3, 7), (4, 5, 8)], [(0, 2, 7), (1, 3, 8), (4, 5, 6)], [(0, 2, 8), (1, 4, 5), (3, 6, 7)], [(0, 3, 4), (1, 5, 7), (2, 6, 8)], [(0, 3, 5), (1, 4, 6), (2, 7, 8)], [(0, 3, 6), (1, 4, 8), (2, 5, 7)], [(0, 3, 7), (1, 6, 8), (2, 4, 5)], [(0, 4, 6), (1, 2, 7), (3, 5, 8)], [(0, 4, 7), (1, 2, 8), (3, 5, 6)], [(0, 4, 8), (1, 2, 6), (3, 5, 7)], [(0, 5, 7), (1, 3, 6), (2, 4, 8)], [(0, 5, 8), (1, 3, 4), (2, 6, 7)], [(0, 6, 7), (1, 2, 5), (3, 4, 8)], [(0, 6, 8), (1, 3, 5), (2, 4, 7)]$

Basically, this is equivalent to Efficiently partition a set into all possible unique pair combinations, but instead of partitioning into pairs, I am partitioning into subsets of size $k$.

Peter Taylor
  • 13,425
user1145925
  • 535
  • 3
  • 12

1 Answers1

5

The existence of a solution is guaranteed by Baranyai's theorem. A proof of the theorem can be found, for instance, in Dieter Jungnickel - Graphs, Networks and Algorithms. The proof is constructive, so an algorithm can be derived from it. The book I mention contains references for explicit constructions in certain special cases.

Furthermore, a Python implementation is given on Stackoverflow. I cannot attest to its correctness.