Computing the union of two sets using Boolean values is simple and efficient. Since the union of two sets is a combination of the members of both sets, we can build a new union s
Computing the union of two sets using Boolean values is simple and efficient. Since the union of two sets is a combination of the members of both
sets, we can build a new union set by Oring the corresponding elements of
the two BitArrays. In other words, a member is added to the new set if the
value in the corresponding position of either BitArray is True.
Computing the intersection of two sets is similar to computing the union;
only for this operation we use the And operator instead of the Or operator.
Similarly, the difference of two sets is found by executing the And operator
with a member from the first set and the negation of the corresponding member of the second set. We can determine if one set is a subset of another set by
using the same formula we used for finding the difference. For example, if:
setA(index) && !(setB(index))
evaluates to False then setA is not a subset of setB.
The BitArray Set Implementation
Write The code for a CSet class based on a BitArray.
Step by step
Solved in 2 steps with 1 images