I have a set S of N elements. Each element is represented by a string of bits of length L.
For example, with L=5, S could be formed by { 01010, 01100, 10100, 00001 }
A pair of elements is compatible if they do not have any bit in common (i.e. if their bitwise AND is zero). For example:
- 01010 is not compatible with 01100, because
01010 & 01100 = 01000
(not zero) - 01010 is compatible with 10100, because
01010 & 01010 = 00000
(zero)
A subset of S is compatible, if the pairwise bitwise AND of all its elements is zero.
For example, the subset { 01010, 10100, 00001 }
is compatible because all the below statements are true
01010 & 10100 = 0
01010 & 00001 = 0
10100 & 00001 = 0
I want to find all possible compatible subsets of S. Given the example of S above, this would be:
{ 01010 }
{ 01100 }
{ 10100 }
{ 00001 }
{ 01010, 10100 }
{ 01010, 00001 }
{ 01100, 00001 }
{ 10100, 00001 }
{ 01010, 10100, 00001 }
What is the best algorithm to achieve that?
The problem could be restated in terms of a graph, where every element of S is a node and compatible elements are connected by edges. In this case the problem becomes that of finding all possible set of nodes fully connected (i.e. were a direct edge exist between each pair of nodes).