Click to See Complete Forum and Search --> : generate subsets


padfoot
July 24th, 2009, 01:45 PM
I'd like to generate all subsets of a given set recursively.
For example ,

A = { 1, 2, 3 }

The subsets will be {}, { 1 }, { 2 }, { 3 }, { 1, 2 }, { 1, 3 }, { 2, 3 }, { 1, 2, 3 }

I'm having trouble coming up with a recursive way to do this.

Could someone help me out in this please ?
Thanks..

Lindley
July 24th, 2009, 02:56 PM
I'm not sure how to do it recursively. The easy way to do it is to count from 0 to 2^3-1, and use the bits to indicate membership.

padfoot
July 25th, 2009, 08:35 AM
I am aware of that technique. I heard that there was a recursive way of doing it and was wondering how to do it.

Zachm
July 26th, 2009, 05:27 AM
Google (http://www.google.co.il/search?rlz=1C1CHMG_iwIL291IL303&sourceid=chrome&ie=UTF-8&q=recursive+find+all+subsets) is your friend.

Tons of links with examples & implementations.

Regards,
Zachm

padfoot
July 27th, 2009, 05:36 AM
Thanks...
I did search on google but I guess I chose the wrong search terms.