MathGroup Archive 2000

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

Search the Archive

Re: generating subsets

  • To: mathgroup at
  • Subject: [mg21604] Re: [mg21588] generating subsets
  • From: BobHanlon at
  • Date: Sun, 16 Jan 2000 22:43:50 -0500 (EST)
  • Sender: owner-wri-mathgroup at


subSets[elements_List] := 
    Flatten[Table[KSubsets[elements, k], {k, 0, Length[elements]}], 1]]

subSets[{a, b, c}]

{{}, {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c}}

Length[subSets[{a, b, c, d, e, f, g, h, i}]] // Timing

{0.25*Second, 512}

Bob Hanlon

In a message dated 1/16/2000 5:22:27 AM, mgass at writes:

>I need an _efficient_  procedure for generating all the subsets
>of a given set.  The procedure should produce output as follows:
>{{}, {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

  • Prev by Date: Re: Plotting A verticle line?
  • Next by Date: Re: entering an equation
  • Previous by thread: Re: generating subsets
  • Next by thread: Re: generating subsets