Sets refresher for Algorithms
Set - is an unordered collection of objects. Usually sets are denoted by capital letters. A set contains its elements.
In the example above, the special character means that the lower case letter is an element of the set . If is not an element of , we write .
When two sets contain the same elements, they are said to be equal. = {e}, = {e} means that or provided that .
Describing sets
Roster method There are a few ways of describing sets. One of them is the roster method. In roster method curly braces are used to list out the elements of a set. = {1,2,3} is a set of positive integers between 1 and 3 inclusive. It is fundamental to note that the order inside set does not matter: {1,3,2} = {1,2,3} because {1,3,2} and {1,2,3}, that is
Also, notice that we separate the elements with comma and we ignore the duplicates.
When the quantity of the elements is large, roster method does not fit well for the purpose. We would not want to list out all 1000 elements when we need to create a set that contains integers from 1 to 1000. One solution is to use three dots ... (which is also called ellipsis). So = {1,2,3 ..., 1000} would describe a set with positive integers 1 to 1000.
Set-builder notation A set can also be described as set-builder notation = {} - set of all objects for which the predicate is true. A set of all even positive integers less than 5 can be written as
Or = {1,2,3 ..., 1000} can be written as
Some sets appear so often that they have special notations for them.
Set | Definition |
---|---|
= {0,1,2,3, } | Natural numbers |
= { -2,-1,0,1,2,3, } | Integers |
= { -2,-1,0,1,2,3, } | Positive integers |
= { and are integers with } | Rational Numbers |
= { is a real number} | Real numbers |
= { is a positive real number} | Positive real numbers |
Empty and Universal sets
For example, = {} =
There are two traps that a lot of people fall into when dealing with sets.
This is incorrect because it is like comparing apples and oranges, one of them is set and the other one is a number 2. = {} This is incorrect as well because the left side is an empty set while the right side is a set with a single element (which is also called a singleton set)
Subsets If every element of set is also an element of set , we can say that is a subset of or . For example,
When an element exists in one set and not in the other, we use the notation:
because the number 2 is not present in the second set
The empty set is a subset of every set
Proper set When every elements of set is also an element of set but there is at least one element in set that is not in set , is a proper subset of . In symbols we write . For example,
Cardinality Cardinality of a set is the number of elements a set contains. For example, = {6,7,8,9} has four elements, therefore the cardinality of the set is 4, often written as || = 4. The empty set has a cardinality of 0: = { } =
A set can be finite and infinite. The cardinality symbol | | above is used to describe finite sets.
Power sets Let's say there is a set which contains and :
If wanted to get the all subsets of set , they would be the followings:
Now, the power set of , is the set of all subsets. It is denoted by the special sign
If the size of a set is written as
then the size of a power set is