Professional Documents
Culture Documents
Unit 4
SETS
What is a set?
A set is a unordered collection of “objects”
People in a class: {Ahmed, Omar, Samy }
Cities in Jordan: {Amman, Tafila, Irbid, … }
Sets can contain non-related elements: {3, a, red, Sameer}
{ 2.1, π, 0, -6.32, e }
2
Properties of sets
Order does not matter
{1, 2, 3, 4, 5} is equivalent to {3, 5, 2, 4, 1}
4
Specifying a Set (ii)
A set “contains” the various “members” or “elements”
that make up the set
If an element a is a member (element) of a set S, we use then
notation
aS
4 {1, 2, 3, 4}
If not, we use the notation
aS
7 {1, 2, 3, 4}
R is the set of real numbers (it includes all the whole numbers,
rational numbers, irrational numbers such as √2 (1.41421356...)
What is Q ? If Q = {p/q | p Z, q Z, q ≠ 0}
Q is the set of rational numbers
Any number that can be expressed as a fraction of two integers
(where the bottom one is not zero)
6
The Universal Set
Venn Diagrams
Represents sets graphically
The rectangle represents the universal set
Circles represent the set(s)
Consider set V, which is the set of all vowels in the alphabet
The individual elements
are usually not written b c d f
in a Venn diagram g h j
k l m
n p q a e i
r s t o u
v w x
y z
8
Sets of Sets
Sets can contain other sets
S = { {1}, {2}, {3} }
T = { {1}, {{2}}, {{{3}}} }
V = { {{1}, {{2}}}, {{{3}}}, { {1}, {{2}}, {{{3}}} } }
How many elements does the set V have ?
only 3 elements!
≠ { } why ?
The first is a set of zero elements (Empty)
The second is a set of 1 element (Singleton)
Replace by { }, and you get: { } ≠ {{ }}
It’s easier to see that they are not equal that way
10
Set Equality, Subsets
Two sets are equal if and only if they have the same elements
x (x A x B)
{1, 2, 3, 4, 5} = {5, 4, 3, 2, 1}
{1, 2, 3, 2, 4, 3, 2, 1} = {4, 3, 2, 1}
Two sets are not equal if they do not have the same elements
{1, 2, 3, 4, 5} ≠ {1, 2, 3, 4}
Proper Subsets
If S is a subset of T, and S is not equal to T, then S is a
proper subset of T
A proper subset is written as S T
Let T = {0, 1, 2, 3, 4, 5}
If S = {1, 2, 3},
12
Example: Answer the following questions by Yes or No
{1, 2, 3}?
Yes
{1, 2, 3}?
No
{, 1, 2, 3}?
Yes
{, 1, 2, 3}?
Yes
{x} {x}?
No
Slide 13
Set Cardinality
The cardinality of a set is the number of elements
in a set, written as |A|
Examples
Let R = {1, 2, 3, 4, 5}. What’s |R|
|R| = 5
|| =
0
Let S = {, {a}, {b}, {a, b}}. What’s |S|
Then |S| = 4
14
Power Sets
Given the set S = {0, 1}. List all the possible subsets of S?
(as it is a subset of all sets), {0}, {1}, and {0, 1}
The power set of S (written as P(S)) is the set of all the subsets
of S
P(S) = { , {0}, {1}, {0,1} }
Note that |S| = 2 and |P(S)| = 4
If a set has n elements, then the power set will have 2n elements
Cartesian Product
A Cartesian product is a set of all ordered 2-tuples where each “part” is from
a given set.
Denoted by A x B, and uses parenthesis (not curly brackets)
NOTE THAT A x B ≠ B x A
Since B x A = { (0, a), (0, b), (1, a), (1, b) }
16
Cartesian Product of many sets
The Cartesian product of the sets A1, A2, ... , An is
A1 A2 … An = {(a1, a2, ... , an) | ai Ai for i = 1,2, ...,n}
Example
A = {0, 1}
B = {1, 2}
C = {0, 1 2}
ABC={ (0, 1, 0), (0, 1, 1), (0, 1, 2),
(0, 2, 0), (0, 2, 1), (0, 2, 2),
(1, 1, 0), (1, 1, 1), (1, 1, 2),
(1, 2, 0), (1, 2, 1), (1, 2, 2) }
17
18
Set Operations: Union
Further examples
{1, 2, 3} U {3, 4, 5} =
{1, 2, 3, 4, 5}
{a, b} U {3, 4} =
{a, b, 3, 4}
{1, 2} U =
{1, 2}
19
AU =
A Identity law
AU U=
U Domination law
AU A=
A Idempotent law
AU B=BUA Commutative law
AU (B U C) = (A U B) U C Associative law
=AUBUC
20
Set Operations: Intersection
Examples
{1, 2, 3} ∩ {3, 4, 5} =
{3}
{a, b} ∩ {3, 4} =
{1, 2} ∩ =
21
A∩U=
A Identity law
A∩=
Domination law
A∩A=
A Idempotent law
A∩B=B∩A Commutative law
A ∩ (B ∩ C) = (A ∩ B) ∩ C = A ∩ B ∩ C Associative law
22
Disjoint Sets
Formal definition for disjoint sets:
two sets are disjoint if their intersection is the empty
set (have no common elements)
Example: which of the following sets are disjoint ?
{1, 2, 3} and {3, 4, 5} are
not disjoint
and are
disjoint! because their intersection is the empty set
23
{a, b}
{1, 2} - =
{1, 2}
24
Complement Sets
Formal definition for the complement of a set:
A = Ac = { x | x A }
Or Ac = U – A, where U is the universal set
Example:
Assuming U = Z, find:
{1, 2, 3}c =
{ …, -2, -1, 0, 4, 5, 6, … }
{a, b} =
c
Z
Let U is the set of all positive integers and A = {x | x > 10} find AC
Ā = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
25
(Ac)c =
A Complementation law
A U Ac =
U Complement law
A ∩ Ac =
Complement law
26
Symmetric difference
Symmetric Difference of two sets A & B is the set of
elements that belong to either set A or set B but not
both.
AB = {x | (x Є A) (x Є B)} .
A B = (A U B) − (A ∩ B)
= (A − B) U (B − A)
27
Set identities
A = A AU = U
Identity Law Domination law
AU = A A =
AA = A Idempotent
(Ac)c = A Complement Law
AA = A Law
AB = BA Commutative (AB)c = AcBc
De Morgan’s Law
AB = BA Law (AB)c = AcBc
A(BC) A(BC) =
= (AB)C Associative (AB)(AC)
Distributive Law
A(BC) Law A(BC) =
= (AB)C (AB)(AC)
A(AB) = A Absorption A Ac = U
Complement Law
A(AB) = A Law A Ac =
A - B = A Bc
28
How to Prove a Set Identity
Four methods:
1. Use the set identities
29
A B
A∩B
B-(B-A) B-A
30
Proof by Set Identities
Use set identities to proof that A B = A - (A - B)
Proof:
A - (A - B)
= A - (A Bc)
= A (A Bc)c
= A (Ac B)
= (A Ac) (A B)
= (A B)
=AB
31
x (A B)c
x (A B)
(x A B)
(x A x B)
(x A) (x B)
xAxB
x A c x Bc
x A c Bc
32
Proof by Builder Notation
Prove A B A B using builder notation
A B {x | x A B} (def of complement)
{x | ( x ( A B ))} (def of not belong to)
{x | ( x A x B )} (def of intersecti on)
{x | ( x A) ( x B )} (De Morgan' s law)
{x | x A x B} (def of not belong to)
{x | x A x B} (def of complement)
{x | x A B} (def of union)
A B
33
34
Generalized Union and Intersection
{0,1,2,3,4,6,8,9}
A⋂B⋂C=
{0}
35
General Cases
n
A1 A2 An Ai
Union: i 1
n
Intersection A1 A2 An Ai
i 1
Union: A1 A2 An Ai
i 1
Intersection: A1 A2 An Ai
i 1
36
Computer Representation of Sets
Slide 37
Example 1
Let U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} and the
ordering of elements of U is in the increasing order,
that is, ai = i
What bit strings represent the following subsets of U:
1. All odd integers in U 12 3456 78910
10 1010 1010
2. All even integers in U
01 0101 0101
Slide 38
Example 1 (cont.)
1. The bit string that represents the set of odd integers
in U, namely, {1, 3, 5, 7, 9}, has bits in positions first,
third, fifth, seventh, and ninth set to 1, and to zero
elsewhere.
10 1010 1010
2. The string representing the subset of all even integers
in U, namely, {2, 4, 6, 8, 10}, is
01 0101 0101
3. The string representing the set of all integers in U that
do not exceed 5, namely, {1, 2, 3, 4, 5}, is
11 1110 0000
Slide 39
Example 2
let U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. If the bit string for
set A = {1, 3, 5, 7, 9} is 10 1010 1010, what is the bit
string for the complement of this set?
Solution
The bit string for the complement of this set is
01 0101 0101,
which corresponds to the set {2, 4, 6, 8, 10}
Slide 40
Example 3
Let U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. If the bit strings for
the sets {1, 2, 3, 4, 5} and {1, 3, 5, 7, 9} are 11 1110 0000
and 10 1010 1010, respectively.
Find the bit string for union and intersection of these sets.
Solution
The bit string for the union of these sets is
11 1110 0000 10 1010 1010 = 11 1110 1010,
corresponds to the set {1, 2, 3,4, 5, 7, 9}