October 2025
Intermediate to advanced
485 pages
13h 2m
English
Because we’re talking about sets, it’s worth highlighting some of the most common set operations. These are the operations known as union, intersection, and difference. To keep things simple, I’ll demo these operations using single integers as bit vectors, rather than using an array of integers.
The union of two sets is a third set that contains all the values from the first two sets combined. For example:
| | Set A: {0, 3, 7} |
| | Set B: {2, 3, 6} |
| | |
| | Union: {0, 2, 3, 6, 7} |
Note that the value 3 only appears once in the union. Although both Set A and Set B contain a 3, the union set contains only one instance of 3. This again is because a set, by definition, does not hold duplicate values.
Thanks to bitwise operators, ...
Read now
Unlock full access