Efficient Algorithm for Enumerating Combinations

In summary, the conversation discusses the issue of enumerating all combinations of an underlying set with special features. The problem is to generate all combinations while using the underlying numbers at most once. The speaker mentions implementing a recursive algorithm, but it has proven to be inefficient for larger sets. They ask for suggestions on a more efficient algorithm, specifically an n choose m algorithm for unordered sets. The potential solution suggested involves generating binary arrays for each set and using a reduction function to generate a variable length array of indexes.
  • #1
Soveraign
55
0
I am facing an issue in my research where I need to enumerate all combinations of an underlying set. BUT the set has some special features. Here is an example:

Given a set {A,B,C,D,E, F} where each item in the set consists of two values. Something like:

A = (1,2)
B = (3,4)
C = (5,6)
D = (1,6)
E = (3,5)
F = (1,3)

Now, my task is to generate (quickly) all combinations of the items in the set where you use the underlying numbers at most once. In the above example, the resulting subsets would be:

{A, B, C}
{A, E}
{B, D}
{C, B}
{D, B}
{D, E}

...and maybe a few others. But hopefully this illustrates what I mean. When starting this problem, I implemented a very inefficient (but complete) recursive algorithm that enumerated all combinations (including order) and just eliminated the duplicates. But this has proven to be untenable now that my set size is in the 30's and the underlying set of numbers is nearly 20.

I realize that this specific problem has maybe not been pursued in Comp Sci, and that it can be considered a special case of n choose m where order doesn't matter. So my question to you all would be, what is the most efficient n choose m algorithm out there (for unordered sets)? or even better, has my problem been solved by someone else already?

Thanks!
Brian
 
Technology news on Phys.org
  • #2
You could generate a set of binary arrays for each set, where the arrays represent valid combinations (0=invalid because of duplicate, 1=valid because no duplicates). Using your example:

array[0] = {0, 1, 1, 0, 1, 0} // A|A no A|B yes A|C yes A|D no A|E yes A|F no
array[1] = {1, 0, 1, 1, 0, 0} // B|A yes B|B no B|C yes B|D yes B|E no B|F no
...

then for each loop that tests all combinations, you can "and" the arrays for specific combinations. For example, when testing A|B|?, you can "and" array[0] & arrray[1] to get an arrary of 0's and 1's for all sets that are not duplicates of A|B.

You might want an APL like reduction function to generate a variable length array of indexes

{0 1 1 0 1 0} / {0 1 2 3 4 5} => {1 2 4}
{1 0 1 1 0 0} / {0 1 2 3 4 5} => {0 2 3}
{0 1 0 0 0 1} / {0 1 2 3 4 5} => {1 5}
{0 0 0 0 0 0} / {0 1 2 3 4 5} => {}

For C, you'd need to store the length of an array of indexes:

Not sure what else you could do here.
 
Last edited:

Related to Efficient Algorithm for Enumerating Combinations

1. What is enumerating combinations?

Enumerating combinations is a mathematical process of listing all the possible combinations of a given set of elements. It involves selecting a certain number of elements from a larger set without considering the order in which they are selected.

2. Why is enumerating combinations important?

Enumerating combinations is important in various fields such as mathematics, statistics, and computer science. It helps in solving problems related to probability, counting, and data analysis. It is also used in creating efficient algorithms for solving complex problems.

3. How do you calculate the number of combinations?

The number of combinations can be calculated using the formula nCr = n! / (r! * (n-r)!) where n is the total number of elements and r is the number of elements selected. For example, if there are 5 elements and we want to select 3 of them, the number of combinations would be 5C3 = 5! / (3! * (5-3)!) = 10.

4. What is the difference between combinations and permutations?

Combinations and permutations are both methods of counting the number of ways to select elements from a set. However, the main difference is that combinations do not take into account the order of the elements, whereas permutations do. In combinations, the order does not matter, while in permutations, the order of the elements is important.

5. How can enumerating combinations be applied in real life?

Enumerating combinations has various real-life applications. For example, it can be used in lottery and gambling to calculate the odds of winning. It is also used in genetics to analyze the possible combinations of genes in a given population. In computer science, it is utilized in creating efficient algorithms for tasks such as data compression and encryption.

Similar threads

  • Programming and Computer Science
Replies
6
Views
1K
Replies
9
Views
1K
  • Programming and Computer Science
Replies
1
Views
979
  • Set Theory, Logic, Probability, Statistics
Replies
8
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
3
Views
1K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
8
Views
3K
Replies
1
Views
1K
Back
Top