2
$\begingroup$

This question already has an answer here:

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$

marked as duplicate by jkuczm, Feyre, user31159, m_goldberg, ilian Sep 10 '16 at 20:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ Have you seen this? $\endgroup$ – J. M. will be back soon Jun 16 '16 at 13:41
  • $\begingroup$ Is this a Mathematica-specific question? $\endgroup$ – Yves Klett Jun 16 '16 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 Jun 16 '16 at 13:48
  • 4
    $\begingroup$ Related: Alternative to Subsets to generate k-combinations $\endgroup$ – jkuczm Jun 16 '16 at 22:52
  • $\begingroup$ @jkuczm That seems close enough to consider a duplicate. Do you disagree? $\endgroup$ – Mr.Wizard Jul 11 '16 at 16:45
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$
  • $\begingroup$ Great! I guess to use Nest and hope it will work. $\endgroup$ – lesobrod Jun 16 '16 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 Jun 16 '16 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 Jun 16 '16 at 19:06
  • $\begingroup$ @Bill You mean NextSubset from Combinatorica? $\endgroup$ – Szabolcs Jun 16 '16 at 19:08
  • $\begingroup$ @Szabolcs Yes, which was why I included the hint to click on Details. $\endgroup$ – Bill Jun 17 '16 at 16:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.