Saturday, March 26, 2011

powerSet -- binary approach


The binary approach just means you're considering each element of the original set(e) as a bit value of a binary number. So if you have an original set of four elements(A, B, C, D) you would consider each one a bit value.

A - 00000001
B - 00000010
C - 00000100
D - 00001000

The size of a power set is calculated by 2^N of the original set. So in this case the size of the power set will be 2^4 or 16. This means that you must create sixteen elements for your power set with binary values starting at 0 and ending at 15 in binary. For each binary value you would add the elements of the original set which have similar bits.

Example:

00000000 - (O) - {Empty Set}
00000001 - (1) - {A}
00000010 - (2) - {B}
00000011 - (3) - {A, B}
00000100 - (4) - {C}
00000101 - (5) - {A,C}
00000111 - (6) - {A,B,C}

No comments:

Post a Comment