What are Sets?
YouTube VideoA set is a collection of elements that are usually related to each other. They can be sets of numbers, letters, people, cars, or even sets themselves! Thus, the elements stored in a stack, queue or list can all be considered as sets. When we define the elements in a set, we typically enclose them in curly brackets as follows.
Here,
Sets do have a few key properties:
- There are no duplicates allowed; we canāt add another Emily to our set above, and
- The elements in a set are unordered; Don doesnāt come before or after Huichen in the set.
There are also a couple of important sets that we need to know.
- The universal set,
, is the set of all elements in what we call the āuniverse of interestā. However, this āuniverse of interestā is relative to the problem at hand; in our example above it could be the set of all people, the set of all students, etc. - The empty set, usually written as
or{}
is the set that contains, well nothing! There is exactly one empty set across all āuniverses of interestā.
Visualizing Sets
If we want to visualize sets and the relationships between them, we can view them using a Venn Diagram as shown below.
The drawing is equivalent to saying the following.
If we overlap the two sets so that the common elements (in this case, 15 and 32) are in the overlapping section, we see that we do not get two copies of 15 and 32, but that we have just one copy of each. Thus, we have preserved the property that sets do not have duplicates. This overlapping area is called the intersection of the two sets.
In the following operations on sets, we will use variants of the diagram below, which shows set