I am looking for an algorithm that, given an array of elements, for example [1,2,3]
will output all possible combinations of groups of these elements. It is trivial to find all possible groups.
In this example, all possible groups will be:
[1], [2], [3], [1,2], [1,3], [2,3], [1,2,3]
Proceeding from this, I would like to find all possible combinations of these groups, and every combination of these groups should contain all provided elements. E.g.:
[[1],[2],[3]], [[1,2],[3]], [[1,3],[2]], [[1],[2,3]], [[1,2,3]]
The problem I'm running into here, is that there should be no duplicates. So, for example, a combination of [1] and [1,2] shouldn't be valid. And I'm thinking that it will be too expensive to check for the presence of duplicates by iterating over two arrays.
For additional information, I will deal with arrays of 12-13 elements.
Please advise if you know the best algorithm for this.