0

I'm trying to do a reverse binomial coefficient calculation in which I get a set of random combinations of (n,r), then I must be able to determine any n-Choose-r(n,r) in the set or subsets. For e.g. if user inputs following set: {(1,2,3) (1,2,4) (1,3,4) (2,3,4)}, the program must detect nCr(3,4).

To do so, First I obtain the

all_combinations = nCr(subset_length,input_set_length) 

which in this case is nCr(3,4) = 4.

Then, I calculate the frequency of each element in form of [element:frequency] as follows.

fs = [1:3], [2:3], [3:3], [4:3]

Finally,

if (length(fs) != all_combinations ) return;
foreach(element in fs)
   if( count(fs.elements) != subset_length ) return;
print 'found nCr:' + subset_length + ',' + input_set_length  

frequency of all elements is equal to subset length, I conclude it's a full combination set.

However, it seems to be incapable of detecting complex cases. For example consider following case:

{(1,2,3) (1,2,4) (1,3,4)}

It's not hard to see there is a fixed element as 1 and a combination of nCr(3,2) in the subsets

{(2,3) (2,4) (3,4)}

I believe there should be better way to detect binomial coefficients recursively out there. Any help is highly appreciated.

mr-ma
  • 199
  • 13
  • Find the fixed elements by intersecting the input sets, then remove them and do the previous algorithm? – David Eisenstat Feb 08 '15 at 13:09
  • @DavidEisenstat good shot. But it does not work if there is a nasty element is the input list. Consider this case: {(1,2) (1,3) (1,4) (2,3)} it should return: 1 as fixed element along nCr(3,1) for following set:(3) (2) (4). But intersecting with the nasty (2,3) will eliminate 2 and 3 from the candidate list... – mr-ma Feb 08 '15 at 13:23

0 Answers0