-
generate subsets
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..
-
Re: generate subsets
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.
-
Re: generate subsets
I am aware of that technique. I heard that there was a recursive way of doing it and was wondering how to do it.
-
Re: generate subsets
Google is your friend.
Tons of links with examples & implementations.
Regards,
Zachm
-
Re: generate subsets
Thanks...
I did search on google but I guess I chose the wrong search terms.