MathGroup Archive 2000

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

Search the Archive

Re: generating subsets

  • To: mathgroup at
  • Subject: [mg21612] Re: [mg21588] generating subsets
  • From: "Tomas Garza" <tgarza at>
  • Date: Sun, 16 Jan 2000 22:43:57 -0500 (EST)
  • Sender: owner-wri-mathgroup at

Michael Gass [mgass at] 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:

<< DiscreteMath`Combinatorica`
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