Google Answers Logo
View Question
 
Q: Enumeration of Combinations ( No Answer,   0 Comments )
Question  
Subject: Enumeration of Combinations
Category: Computers > Algorithms
Asked by: quantumanenome-ga
List Price: $10.00
Posted: 23 Sep 2004 14:05 PDT
Expires: 24 Sep 2004 01:38 PDT
Question ID: 405435
Enumeration of Combinations

C(m,n) gives the number of combinations of m things taken n at a time,
or how many m bit numbers have exactly n bits set, computed by m! /
((m-n)! * n!).

I already know how to iteratively enumerate all combinations one by
one in lexigraphical order.
(http://www.caam.rice.edu/~dougm/twiddle/EnumComb.html)

What I need is to generate any given element given the index, and the
inverse to return the index given the combination.

Both algorithms need to be at worst O(m), or take m or less iterations.

I have already solved this for C(m, 2), but cannot extract a
generalized algorithm for C(m, n).

Solution for C(m, 2):

If bits Y and X are set,
I = (Y*Y - Y)/2 + X

If you know the index I,
Y = 1 + ((sqrt(1 + 8*I) - 1) / 2)
and using the above equation solving for x
X = I - (Y*Y - Y)/2
Set bits X and Y


for example, the 8th element (zero based!) in the C(7, 2) set would be 00010100.
for example, the 0th element will be 0000011.


It is not required that the combinations be listed in any particular
order, as long as the inverse function properly returns the original
index.

Clarification of Question by quantumanenome-ga on 24 Sep 2004 01:37 PDT
I have solved this myself.
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy