Unions and Intersections
The set generator notation creates new set. Although the notation only generate sets, it is powerful enough define basic set operations: union, intersection, and difference.
The union of two sets and is the set of all things which are elements of , , or both.
The union operator is useful for combining two sets of things into one such as films seen by two persons can be represented as sets and . Now that if they are to go cinema, they can create a new set to determine the films either of them has seen.
Two young friends are trying decide a film to watch, but they can only choose from films either of them owns. Friend is a Star Wars fan and bought films
the friend loves superhero films and has a collection
The films they can watch is a union which forms a new set
We can also consider a "dual" operation to union. This is the operation that forms the set of all elements that are elements of and are also elements of . This operation is called intersection. Two sets are called disjoint if their intersection is empty.
The intersection of two sets and , written , is the set of all things which are elements of both and .
A practical use is finding common elements of things, e.g. in dating finding common interests and expectations is important. You may discuss food you both like or activities you would enjoy doing together. A way to represent this situation is to define an intersection of interests . If there is a set of things you cannot do due to life situation e.g. having children, you can define a set of things you can do using difference operation.
The set difference is the set of all elements of which are not also element of , i.e,
Implement set data structure, and the basic operations described in this section.