Week#2.2-Set Theory
Week#2.2-Set Theory
1
Outline on sets
Basics
Specify a set by enumerating all elements
Notations
Cardinality
Venn Diagram
Relations on sets: subset, proper subset
Set builder notation
Set operations
Principle of Inclusion/Exclusion
Applications of Venn diagram
2
Principle of Inclusion/Exclusion
We are often interested in finding the cardinality of a union of two finite
sets A and B.
Note that |A| + |B| counts each element that is in A but not in B or in B but
not in A exactly once and each element that is in both A and B exactly twice.
Thus, if the number of elements that are in both A and B is subtracted from |A| + |B|,
elements in A ∩ B will be counted only once.
Hence,
3
Principle of Inclusion/Exclusion
| A B || A | | B | | A B |
Also,
| A || A B | | B | | A B |
Principle of Inclusion & Exclusion
|A B| = |A| + |B| - |A B|
The above equation represents the
principle of inclusion and exclusion for two
sets A and B.
The name comes from the fact that to
calculate the elements in a union, we
include the individual elements of A and B
but subtract the elements common to A
and B so that we don’t count them twice.
This principle can be generalized to n sets.
PF Museum or Maritime Museum
Of the 28 students in a class,
23 have visited one or both
12 have visited PF (Only PF + Both PF & Maritime
Museum)
9 have visited PF and Maritime Museum
How many have visited Maritime Museum?
How many have visited only PF Museum?
Solution:
|P M| = |P| + |M| - |P M|
23= 12+|M|-9=> |M|=20
|P - M| = |P| - |P M|
12-9=3
Example 1
A Software house needs to hire 20 developers
to handle frontend developers jobs and 30
developers for backend developer, of those
hired, 5 are expected to perform the job of
both types.
How many developers must be hired?
Solution:
A= 20 frontend developers
B= 30 backend developers
|AnB|=5, |AUB|=?
7
Example 2
Example 2: How many integers from 1 to 1000 are
either multiples of 3 or multiples of 5?
Assume A = set of all integers from 1 to 1000 that are
multiples of 3.
Assume B = set of all integers from 1 to 1000 that are
multiples of 5.
A B = The set of all integers from 1 to 1000 that are
multiples of either 3 or 5.
A B = The set of all integers that are both multiples of 3
and 5, which also is the set of integers that are multiples
of 15.
To use the inclusion/exclusion principle to obtain |
A B|, we need |A|, |B| and |A B|.
Exmple 02: Suggested Solution
Multiples of 3 (|A|):
The numbers are 3, 6, 9, ..., 999.
Formula: 1000/3=333, So, |A| = 333.
Multiples of 5 (|B|):
The numbers are 5, 10, 15, ..., 1000.
Formula: 1000/5==200.
So, |B| = 200.
Multiples of 15 (|A ∩ B|):
The numbers are 15, 30, 45, ..., 990.
Formula: 1000/5=66
So, |A ∩ B| = 66.
From the principle, we have the number of
integers either multiples of 3 or multiples of 5
from 1 to 1000 given by
|A B| = 333 + 200 – 66 = 467.
9
Disjoint Sets
Universal set S
S: the domain
Sets A and B
subsets of a universal set S
If A and B are disjoint
|A B| = |A| + |B|
Example: A={3, 5, 7, 9}, B={2,4,6}
What if A and B are not disjoint?
Disjoint sets
11
Exercises
Exercise 1: A = {1, 3, 5, 7}, B={0,2,4,6,8}
How many elements in A B?
A. 0 B. 8 C. 9 D. not sure
How many elements in A B?
A. 0 B. 2 C. 9 D. not sure
Exercise 2: A = {2, 3, 5, 7, 11}, B={1, 3, 5, 7,
9}
How many elements in A B?
A. 10 B. 5 C. 7 D. not sure
How many elements in A B?
A. 0 B. 3 C. 5 D. not sure
Exercise
A = {2, 3, 5, 7, 11,13}, B={1, 3, 5, 7, 9}
What is |A B| + | A B|?
A. 11 B. 6 C. 5 D. not
sure
What is |A B|?
A. 0 B. 3 C. 5 D. not
sure
What is |A B| ?
A. 11 B. 8 C. 6 D. 5 E. not sure
Example 3: Inclusion/Exclusion
for three Sets
Example 3: In a class of students
undergoing a computer course the
following were observed.
Out of a total of 50 students: 30 know Java, 18
know C++, 26 know Basic, 9 know both Java and
C++, 16 know both Java and Basic, 8 know both
C++ and Basic, 47 know at least one of the three
languages.
From this we have to determine
a. How many students know none of these
languages?
b. How many students know all three languages?
Example3 Solution
a. We know that 47 students know at least one of the three
languages in the class of 50. The number of students who
do not know any of three languages is given by the
difference between the number of students in class and
the number of students who know at least one language.
• Hence, the students who know none of these languages = 50
– 47 = 3.
b. Students know all three languages, so we need to find |A
B C|.
A = All the students who know Java in class.
B = All the students who know C++ in the class.
C = All the students who know BASIC in class.
We have to derive the inclusion/exclusion formula for three
sets
|A B C| = |A (B C)| = |A| + |B C| - |A (B C)|
Example3 Solution (Continued)
|A B C| = |A (B C)| = |A| + |B C| - |A (B C)|
= |A| + |B| + |C| - |B C| - |(A B) (A C)|
= |A| + |B| + |C| - |B C| - (|A B| + |A C| - |A B C|)
= |A| + |B| + |C| - |B C| - |A B| - |A C| + |A B C|
Given in the problem are the following:
|B C| = 8
|A B| = 9
|A C| =16
|A B C| = 47
Hence, using the above formula, we have
47 = 30 + 26 + 18 -9 -16 -8 + |A B C|
Hence, |A B C| = 6
Now we use this result to fill the venn diagram we
have:
6 knows all three languages
9 know both Java and C++ but not basic=9-6
Java and C++=3
16 know both Java and Basic but not C++ =16-6