I have an n-element set, and I want to consider the families of its k-elements of subsets of fixed size s. For example, if n = 3, k = 1, s = 2, we have the following families:
{{1}, {2}}, {{1}, {3}}, {{2}, {3}}
In my problem, n, k, s are not so small, for example. s = n = 50, k = 20.
Say, all such families are ordered lexicographically (or indeed in any clearly specified order). I want to have an effective way to get a family by its number.
I thought about using itertools, but I am afraid that it will not work with such large numbers. Maybe I need to implement something, but I don’t understand how to do it. I have only the following idea: list all the subsets of k-elements of a set of n-elements (there is an effective algorithm for obtaining the i-th element through i). Then we list all s-element subsets of the comb (n, k) -element set using the same operation. Now we need to generate a number in the range (0, comb (comb (n, k), s)) and first include it in the number of subsets of s-elements, and then in the family of sets of k-elements.
However, this approach looks a bit more complicated. Maybe easier?
source
share