Sets Notes
Sets Notes
2
Why we learn Set Theory?
• Important language and tool for
reasoning in computer science:
– Indivisible from Logic where
Computer Science has its roots
– Foundation of topics like functions and
relations
– Even classical problem in AI,
classification is to determine members
in a set
3
Content
• Sets
• Venn Diagram
• Set operations
• Elements in a set
• Cartesian products
4
Sets
Sets - Collections of distinct objects
5
Sets
Sets - Collections of distinct objects
6
Member of a set
7
Example of Sets
• Integers
ℤ = { …, -3, -2, -1, 0, 1, 2, 3, … }
• Natural numbers
ℕ = { 1, 2, 3, … }
• Rational numbers
ℚ → Quotients of integers, e.g. ¼ , -0.7, 5.5
• Real numbers
ℝ → All numbers from -∞ to +∞ , i.e. -0.7, π
8
Equal sets
2 sets are equal if they contain the same elements
A = { 1, 3, 5 }
B = { 5, 1, 3 }
C = { 3, 1, 1, 5 }
9
Equal sets
2 sets are equal if they contain the same elements
A = { 1, 3, 5 } Otherwise,
X≠Y
B = { 5, 1, 3 }
X≠Z
C = { 3, 1, 1, 5 } Y≠Z
A=B=C e.g.
X={1,2}
Y={1,3}
Order and occurrence Z={1,2,3}
are irrelevant
10
Set description
We may describe a set like this:
A = { 1, 2, 3, ... }
However, this “...” form is not precise enough.
11
Set description
We may describe a set like this:
A = { 1, 2, 3, ... }
However, this “...” form is not precise enough.
12
Set description
We may describe a set like this:
A = { 1, 2, 3, ... }
However, this “...” form is not precise enough.
18
Empty Set
• Also called null set or void set.
• symbol : Ø or {}
• Example:
if A = { x | x ∈ ℕ and x < 0}
A = {}
• Ø is a subset of all sets.
19
Power Set
• The set of all subsets of a set.
• if S is a set, its power set is P(S).
• Example:
if S = {1, 2, 3}
P(S) = { {1}, {2}, {3}, {1,2}, {1,3}, {2,3},
{1,2,3}, Ø }
20
Exercise
• List 5 elements in each of the sets:
A = { 2n+1 | n ∈ ℕ }
{ n | n ∈ ℕ and n is divisible by 5}
{r∈ ℚ|0<r<1}
{ k ∈ ℕ | k+1 is prime number }
P({a,b,c,d,e})
{ 1/r | r = 1, 2, 3, 4, 5 }
21
Venn Diagrams
• An illustration of sets.
• Example, a set A in universe U:
U
A
22
Union, ⋃
23
Union, ⋃
24
Union, ⋃
Exercise: S = {a, b, c, d }
T = {a, d, e, f }
If P = S ⋃ T , P = ?
a) {a, b, c, d, e, f } b) {a, b, c, d, a, d, e, f }
c) {a, a, b, c, d, d, e, f } d) {a,d}
25
S⋃T
U
S T
26
Intersection, ⋂
27
Intersection, ⋂
28
Intersection, ⋂
Exercise:
S = {a, b, c, d }
T = {a, d, e, f }
If Q = S ⋂ T , Q = ?
29
S ⋂ T ??
U
S T
30
Difference, -
Exercise:
S = {a, b, c, d }
T = {a, d, e, f }
If V = S - T , V = ?
31
S-T
U
S T
32
Complement
• If A is a set, the complement of set A,
with notation A, Ac or A', is defined as :
Example:
If the universe is natural numbers, and
P is all the odd numbers,
P' is all the even numbers.
33
A
U
A
34
Set Identities
35
36
Exercise
Assume:
Find
37
Exercise
Shade the area represented by:
U
A B
38
Order of a Set
• If A is a set, n(A) is the order of a set
→ the number of elements in the set A.
• Also explained as the size of a set.
• Examples:
A = { a, b, c, d, e }
n(A) = 5
B=Ø
n(B) = 0
39
The Number of Elements
in a Set
U
A B
U A B
42
Example
• Let A = { a, b, c, d, e } and B = { a, e, g,
u, w, z }. Find n(A), n(B), n(A∩B) and
n(A U B).
U
A B
a g u
b c d e w z
44
Exercise (Solution)
• if A is set of brown eyes
B is set of black hair
• n(A) = 25 n(B) = 15
• n(A∩B) = 10 n(AUB)= 23
45
Exercise (Solution)
• if A is set of brown eyes
B is set of black hair
• n(A) = 25 n(B) = 15
• n(A∩B) = 10 n(AUB)= 23
people interviewed have either brown eyes or black hair,
46
Exercise (Solution)
• if A is set of brown eyes
B is set of black hair
• n(A) = 25 n(B) = 15
• n(A∩B) = 10 n(AUB)= 23
people interviewed have either brown eyes or black hair,
11 S
40
a) Buy only a car : 3
b) Buy only a stove : 11
c) Buy a stove and refrigerator, but not a car : 9
d) Buy a stove and a car, but not a refrigerator : 3
e) Buy none of these items : 40
49
Cartesian Products
• Set of all ordered pair of elements
(x,y) where x A and y B denoted by
A X B = { (x,y) | xA and yB } is
called the Cartesian product of A and
B.
• Generally, A X B ≠ B X A
50
Examples
• If A = { a, b}
B = {1, 2, 3}