Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: generating subsets

  • To: mathgroup at smc.vnet.net
  • Subject: [mg21594] Re: [mg21588] generating subsets
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Sun, 16 Jan 2000 22:43:43 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

This is a classic problem for which there are dozen of solutions. My
favourite one is Ilan Vardi's ("Computational Recreations in Mathematica):

subSets[l_List] := Distribute[Map[{{}, {#}} &,  l], List, List, List, Union]

In[5]:=
Subsets[{a, b, c}]

Out[5]=
{{}, {c}, {b}, {b, c}, {a}, {a, c}, {a, b}, {a, b, c}}

Algebraic programs like this one are usually not the fastest possible but
for me this is  easily compensated for by their elegance and readability.

> From: Michael Gass <mgass at bach.math.csbsju.edu>
To: mathgroup at smc.vnet.net
> Date: Sun, 16 Jan 2000 03:56:54 -0500 (EST)
> To: mathgroup at smc.vnet.net
> Subject: [mg21594] [mg21588] generating subsets
> 
> 
> I need an _efficient_  procedure for generating all the subsets
> of a given set.  The procedure should produce output as follows:
> 
> subSets[{a,b,c}]
> produces
> {{}, {a}, {b}, {c}, {a,b}, {a,c}, {b,c}, {a,b,c}}
> 
> I have written a recursive procedure to do this, but
> it takes quite a while to generate, say, the 512 subsets
> of a 9 element set and I need to work with somewhat larger
> sets.
> 
> Thanks
> 
> -- 
> Michael Gass                Department of Mathematics
> phone: 320 363-3090                     St. John's University
> email: mgass at csbsju.edu                 Collegeville, MN  56321-3000
> 
> 
> 
> 
> 



  • Prev by Date: Re: generating subsets
  • Next by Date: Flat, OneIdentity attributes
  • Previous by thread: Re: generating subsets
  • Next by thread: Re: generating subsets