Efficient Algorithm for Enumerating Combinations

  • Thread starter Thread starter Soveraign
  • Start date Start date
  • Tags Tags
    Combinations
AI Thread Summary
The discussion centers on the challenge of efficiently generating all combinations of a set of items, each associated with two numerical values, while ensuring that the underlying numbers are not repeated across combinations. The example provided illustrates a set with items A through F, each linked to pairs of numbers. The initial approach involved a recursive algorithm that generated all combinations and filtered out duplicates, which became impractical as the set size increased.A proposed solution involves creating binary arrays to represent valid combinations, where each element indicates whether a specific combination is valid (1) or invalid due to number duplication (0). By using logical operations on these arrays, one can efficiently determine valid combinations without generating all possible subsets first. This method aims to streamline the process and improve performance, particularly for larger sets. The discussion seeks further insights into the most efficient algorithms for this type of problem and whether similar challenges have been addressed in computer science.
Soveraign
Messages
55
Reaction score
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
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:
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top