2
$\begingroup$

It is well known that the array of subsets of even small set is very big. This leads to problems with machine memory. Is there an effective way to generate subsets sequentially?

$\endgroup$
6
  • $\begingroup$ Have you seen this? $\endgroup$ Commented Jun 16, 2016 at 13:41
  • $\begingroup$ Is this a Mathematica-specific question? $\endgroup$ Commented Jun 16, 2016 at 13:41
  • $\begingroup$ Yes, it's about Mathematica. The answer is interesting, but unwieldy enough. May be in a new version there is a better way? $\endgroup$ Commented Jun 16, 2016 at 13:48
  • 4
    $\begingroup$ Related: Alternative to Subsets to generate k-combinations $\endgroup$ Commented Jun 16, 2016 at 22:52
  • $\begingroup$ @jkuczm That seems close enough to consider a duplicate. Do you disagree? $\endgroup$ Commented Jul 11, 2016 at 16:45

1 Answer 1

4
$\begingroup$

The Subsets function has a third argument to return only some subsets. For example,

Subsets[set, All, {k1, k2}] 

returns the k1th through the k2th subsets. This allows for easy sequential generation in blocks. Please check the documentation for details.

$\endgroup$
6
  • $\begingroup$ Great! I guess to use Nest and hope it will work. $\endgroup$ Commented Jun 16, 2016 at 14:38
  • $\begingroup$ @lesobrod I assume this won't use extra memory, but I haven't actually tested ... you better test this first. $\endgroup$ Commented Jun 16, 2016 at 14:46
  • $\begingroup$ I assume that NextSubset is implemented carefully enough that it does not generate the entire set just to find the next element. Be sure to click on the Details in the documentation to understand the usage. $\endgroup$ Commented Jun 16, 2016 at 19:06
  • $\begingroup$ @Bill You mean NextSubset from Combinatorica? $\endgroup$ Commented Jun 16, 2016 at 19:08
  • $\begingroup$ @Szabolcs Yes, which was why I included the hint to click on Details. $\endgroup$ Commented Jun 17, 2016 at 16:29

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.