Representing finite sets
- Suppose we want to represent a set A⊆{0,1,2,..,w−1}. Example: A={0,3,5,6}
- It can be represented with a bit vector [aw−1,…,a1,a0] where ai=1 if and only if i∈A
Example
- Consider the above set, A={0,3,5,6}
- It can be encoded by the vector, a=[01101001]. Notice that a0=a3=a5=a6=1
Set union and intersection operations
- Boolean operations
| and & correspond to set union and intersection operations when a set is encoded by vectors as shown above.
Example
- Consider two sets:
- A={0,3,5,6} encoded by a=[01101001]
- B={0,2,4,6} encoded by b=[01010101]
- Then the operation a & b=[01000001] encodes A∩B={0,6}
Sources