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?
$\begingroup$ $\endgroup$
6 - $\begingroup$ Have you seen this? $\endgroup$J. M.'s missing motivation– J. M.'s missing motivation2016-06-16 13:41:28 +00:00Commented Jun 16, 2016 at 13:41
- $\begingroup$ Is this a Mathematica-specific question? $\endgroup$Yves Klett– Yves Klett2016-06-16 13:41:29 +00:00Commented 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$lesobrod– lesobrod2016-06-16 13:48:45 +00:00Commented Jun 16, 2016 at 13:48
- 4$\begingroup$ Related: Alternative to Subsets to generate k-combinations $\endgroup$jkuczm– jkuczm2016-06-16 22:52:21 +00:00Commented Jun 16, 2016 at 22:52
- $\begingroup$ @jkuczm That seems close enough to consider a duplicate. Do you disagree? $\endgroup$Mr.Wizard– Mr.Wizard2016-07-11 16:45:53 +00:00Commented Jul 11, 2016 at 16:45
| Show 1 more comment
1 Answer
$\begingroup$ $\endgroup$
6 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.
- $\begingroup$ Great! I guess to use
Nestand hope it will work. $\endgroup$lesobrod– lesobrod2016-06-16 14:38:14 +00:00Commented 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$Szabolcs– Szabolcs2016-06-16 14:46:37 +00:00Commented 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$Bill– Bill2016-06-16 19:06:03 +00:00Commented Jun 16, 2016 at 19:06
- $\begingroup$ @Bill You mean
NextSubsetfrom Combinatorica? $\endgroup$Szabolcs– Szabolcs2016-06-16 19:08:07 +00:00Commented Jun 16, 2016 at 19:08 - $\begingroup$ @Szabolcs Yes, which was why I included the hint to click on Details. $\endgroup$Bill– Bill2016-06-17 16:29:32 +00:00Commented Jun 17, 2016 at 16:29