In some algorithms, it is necessary to perform operations on sets with various data. However, what is a set? A set is a collection of distinct objects without duplicated elements and without a particular order. Therefore, you can only get to know whether a given element is in the set or not. The sets are strictly connected with the mathematical models and operations, such as union, intersection, subtraction, and symmetric difference.
A set can store various data, such as integer or string values, as shown in the following diagram. Of course, you can also create a set with instances of a user-defined class, as well as add and remove elements from the set at any time.
![](https://static.packt-cdn.com/products/9781788833738/graphics/assets/711ea288-1b69-41e1-bc10-ce9441ca8978.png)
Before seeing sets in action, it is a good idea to remind you of some basic operations that can be performed on two sets, named A and B. Let's start with the union and intersection, as shown in the...