0

Possible Duplicate:
How to find all possible subsets of a given array?

I have to find all possible subset of a given array.Do you know any algorithm for this?

Community
  • 1
  • 1
  • 1
    Can you give a small example to clarify what exactly you're expecting for a certain input array? – Kosi2801 Jan 07 '11 at 14:13
  • @duffymo The problem in the referred link is slightly different to this one, I don't think that these are exactly the same problems. – Kosi2801 Jan 07 '11 at 14:22
  • @duffymo, just wasted 5min :/ –  Jan 07 '11 at 14:23
  • for example if I have {1,2,3} subsets are {empty set},{1},{2},{3},{1,2},{1,3},{2,3},{1,2,3} –  Jan 07 '11 at 14:30

1 Answers1

2

This is a long shot, but if you need a function to produce {},{1},{2},{3},{1,2},{2,3},{1,3},{1,2,3} from {1,2,3}. you could generate binary numbers from 0 to 2^count(array)-1 and select array items that correspond to binary digits in generated numbers.

000 -> {}
100 -> {1}
010 -> {2}
110 -> {1,2}
001 -> {3}
101 -> {1,3}
011 -> {2,3}
111 -> {1,2,3}

// left-side binary system aka lazy binary system