2

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?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
lesobrod
  • 1,657
  • 9
  • 14

1 Answers1

4

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.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
  • Great! I guess to use Nest and hope it will work. – lesobrod Jun 16 '16 at 14:38
  • @lesobrod I assume this won't use extra memory, but I haven't actually tested ... you better test this first. – Szabolcs Jun 16 '16 at 14:46
  • 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. – Bill Jun 16 '16 at 19:06
  • @Bill You mean NextSubset from Combinatorica? – Szabolcs Jun 16 '16 at 19:08
  • @Szabolcs Yes, which was why I included the hint to click on Details. – Bill Jun 17 '16 at 16:29
  • @Szabolcs If you could leave a small example in your answer with values ​​would be interesting. At the moment I'm reading on my cell phone and it's not the first time I see this answer when I do a search. – LCarvalho May 01 '17 at 12:00