I need a little bit of algorithmic help to improve the performance of an analysis.
The Problem:
given a set of N many elements X[0], ..., X[N-1]: I need all possible ways of dividing those N elements into M many distinct subsets each with N / M many elements (let us assume N can always be divided by M).
When I refer to a set I mean the mathematic definition of a set. The ordering of elements is of no importance. For example {A, B} is equal to {B, A}.
Example:
N = 6
M = 2
Input := {X0, X1, X2, X3, X4, X5}
Output :=
{X0, X1}, {X2, X3}, {X4, X5}
{X2, X1}, {X0, X3}, {X4, X5}
{X3, X1}, {X2, X0}, {X4, X5}
{X4, X1}, {X2, X3}, {X0, X5}
{X5, X1}, {X2, X3}, {X4, X0}
...
A trivial solution to this problem is to iterate over all permutations of the initial set, for example with Heaps Algorithm, and then divide into equally sized chunks. This however creates more combinations than are needed since changing the order of elements within a set makes no difference to the set but still constitutes a different permutation if the set is represented as an array in a naive implementation of Heaps Algorithm.
What I would like to know is if there is a known algorithm for this problem or for a similar problem. Or perhaps if the approach via the permutation algorithm + filtering is as good as it gets.
If more information is required please ask.
Thank you very much.