Sets Notes

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 51

Sets

Sets : Collections of distinct objects

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

Example: A is a set of Europe countries.

A = { Belgium, France, Netherlands, … }

5
Sets
Sets - Collections of distinct objects

Example: A is a set of Europe countries.

A = { Belgium, France, Netherlands, … }

Name Elements / members


of the set of the set

Normally, we use capital letters to represent sets

6
Member of a set

Symbol of “member of”

Symbol of “not member of”

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.

A better way to describe a set:


A = { x : x is a positive integer }

12
Set description
We may describe a set like this:
A = { 1, 2, 3, ... }
However, this “...” form is not precise enough.

A better way to describe a set:


A = { x : x is a positive integer }
Or, even more “professional”
A = { x | x ∈ ℤ and x > 0 }
13
Set description
• The “|” or “:” can read as “such that”.
• Example:
A = { x : x ∈ ℤ and x > 0 }
A is a set of all x such that X is
integers greater then 0.
• More examples:
B = { x | x ∈ ℝ and 1 ≤ x ≤ 3 }
C = { x2 | x ∈ ℕ }
14
Subset and Proper Subset
• S is a subset of T if
every element in S belongs to T.
S⊆T
• Example:
 Cities in Selangor ⊆ Cities in Malaysia
ℕ ⊆ ℤ ⊆ ℝ
• If S ⊆ T and T ⊆ S
S=T
15
Subset and Proper Subset
• If S is a subset of T, S ⊆ T
but, if S ≠ T
→ S is a proper subset of T
S⊂T
• Example:
if A = {1,2}, B={1,2,3}, C={3,2,1}
A⊆C
A⊂C
B⊆C
B⊂C 16
Subset and Proper Subset
• If S is a subset of T, S ⊆ T
but, if S ≠ T
→ S is a proper subset of T
S⊂T
• Example:
if A = {1,2}, B={1,2,3}, C={3,2,1}
A⊆C Ö
A⊂C Ö
B⊆C Ö
B⊂C ´ 17
Universe
• Universal set, U is the discourse of
discussion.
• Example:
If we are discussing numbers such as
ℕ, ℤ, ℚ and ℝ, all of them belong to
the universe “Number”.
• All ℕ, ℤ, ℚ and ℝ are subsets of U.

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

double counted area, (A∩B) 40


The Number of Elements
in a Set

U A B

double counted area, (A∩B∩C) 41


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

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

n(A)=5, n(B)=6, n(A∩B)=2


n(A U B) = 5 + 6 – 2 = 9 43
Example
• A survey of a group of people indicate
there were 25 with brown eyes and 15
with black hair. If 10 people had both
brown eyes and black hair, and 23
people had neither, how many people
interviewed have either brown eyes or
black hair? How many people in all
were interviewed?

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,

Total people being interviewed


= people with either brown eyes or black hair
+ people had neither
= 30 + 23 = 53
47
Example
• In a survey of 75 customers, 12 indicate they
were going to buy a new car, 18 said they were
going to buy a new refrigerator, and 24 said they
were going to buy a new stove. Of these, 6 were
going to buy both a car and a refrigerator, 4 were
going to buy a car and a stove, and 10 were
going to buy a stove and refrigerator. One person
indicated he was going to buy all 3 items.
a) How many were going to buy only a car?
b) How many were going to buy only a stove?
c) How many were going to buy a stove and refrigerator, but not a car?
d) How many were going to buy a stove and a car, but not a refrigerator?
e) How many were going to buy none of these items?
48
Solution
U
C R
3 5 3
1
3 9

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) | xA and yB } 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}

• A X B = { (a,1), (a,2), (a,3), (b,1), (b,2),


(b,3) }
• B X A = { (1,a), (1,b), (2,a), (2,b), (3,a),
(3,b) }
(a,1) ≠ (1,a)
51

You might also like