Mathematica 9 is now available
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: [mg21612] Re: [mg21588] generating subsets
  • From: "Tomas Garza" <tgarza at mail.internet.com.mx>
  • Date: Sun, 16 Jan 2000 22:43:57 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Michael Gass [mgass at bach.math.csbsju.edu] wrote:

> 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.

This will do what you want:

In[1]:=
<< DiscreteMath`Combinatorica`
In[2]:=
Table[KSubsets[{a, b, c, d, e, f, g, h, i}, j], {j, 0, 9}]

Tomas Garza
Mexico City


  • Prev by Date: Re: entering an equation
  • Next by Date: Re: entering an equation
  • Previous by thread: Re: entering an equation
  • Next by thread: Re: generating subsets