1 2 3 4 .... 1 1 1 1 1 ......... ?
1 2 3 4 ....
Discrete mathematics
Basic Structures: Sets,
Functions, Sequences,
x y ( x y ) Sums, and Matrices
x( | x )
1 Chapter 2
x 1 ?
x
x 1 x ?
RIZOAN TOUFIQ
ASSISTANT PROFESSOR
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
RAJSHAHI UNIVERSITY OF ENGINEERING & TECHNOLOGY
Set Operations
Section 2.2
Section Summary
Set Operations
– Union
– Intersection
– Complementation
– Difference
More on Set Cardinality
Set Identities
Proving Identities
Membership Tables
Union
Definition: Let A and B be sets. The union of the sets A
and B, denoted by A ∪ B, is the set:
Example: What is {1,2,3} ∪ {3, 4, 5}?
Solution: {1,2,3,4,5}
Venn Diagram for A ∪ B
U
A B
Intersection
Definition: The intersection of sets A and B, denoted by
A ∩ B, is
Note if the intersection is empty, then A and B are said
to be disjoint.
Example: What is {1,2,3} ∩ {3,4,5} ?
Solution: {3}
Example:What is {1,2,3} ∩ {4,5,6} ? Venn Diagram for A ∩B
Solution: ∅ U
A B
Complement
Definition: If A is a set, then the complement of the A
(with respect to U), denoted by Ā is the set U - A
Ā = {x ∈ U | x ∉ A}
(The complement of A is sometimes denoted by Ac .)
Example: If U is the positive integers less than 100, what
is the complement of {x | x > 70}
Solution: {x | x ≤ 70}
Venn Diagram for Complement
U
A Ā
Difference
Definition: Let A and B be sets. The difference of A and
B, denoted by A – B, is the set containing the elements
of A that are not in B. The difference of A and B is also
called the complement of B with respect to A.
A – B = {x | x ∈ A x ∉ B} = A ∩B
Venn Diagram for A − B
U
A
B
The Cardinality of the Union of
Two Sets
• Inclusion-Exclusion |A ∪ B| = |A| + | B| − |A ∩ B|
U
A B
Venn Diagram for A, B, A ∩ B, A ∪ B
• Example: Let A be the math majors in your class and
B be the CS majors. To count the number of students
who are either math majors or CS majors, add the
number of math majors and the number of CS majors,
and subtract the number of joint CS/math majors.
Review Questions
Example: U = {0,1,2,3,4,5,6,7,8,9,10} A = {1,2,3,4,5}, B ={4,5,6,7,8}
1. A ∪ B
Solution: {1,2,3,4,5,6,7,8}
2. A ∩ B
Solution: {4,5}
3. Ā
Solution: {0,6,7,8,9,10}
4.
Solution: {0,1,2,3,9,10}
5. A – B
Solution: {1,2,3}
6. B – A
Solution: {6,7,8}
Symmetric Difference
Definition: The symmetric difference of A and B, denoted
by is the set
Example:
U = {0,1,2,3,4,5,6,7,8,9,10} Venn Diagram
A = {1,2,3,4,5} B ={4,5,6,7,8}
What is :
– Solution: {1,2,3,6,7,8}
U
A B
Set Identities
Identity laws
Domination laws
Idempotent laws
Complementation law
Set Identities
Commutative laws
Associative laws
Distributive laws
Set Identities
De Morgan’s laws
Absorption laws
Complement laws
Proving Set Identities
Different ways to prove set identities:
1. Prove that each set (side of the identity) is a subset of the other.
2. Use set builder notation and propositional logic.
3. Membership Tables: Verify that elements in the same
combination of sets always either belong or do not belong to the
same side of the identity. Use 1 to indicate it is in the set and a 0
to indicate that it is not.
Proof of Second De Morgan Law
Example: Prove that
Solution: We prove this identity by showing that:
1) and
2)
Proof of Second De Morgan Law
These steps show that:
Proof of Second De Morgan Law
These steps show that:
Set-Builder Notation: Second
De Morgan Law
Membership Table
Example: Construct a membership table to show that the distributive
law holds.
Solution:
A B C
1 1 1 1 1 1 1 1
1 1 0 0 1 1 1 1
1 0 1 0 1 1 1 1
1 0 0 0 1 1 1 1
0 1 1 1 1 1 1 1
0 1 0 0 0 1 0 0
0 0 1 0 0 0 1 0
0 0 0 0 0 0 0 0
Generalized Unions and
Intersections
Let A1, A2 ,…, An be an indexed collection of sets.
We define:
These are well defined, since union and intersection are
associative.
For i = 1,2,…, let Ai = {i, i + 1, i + 2, ….}. Then,
Computer Representation of
Sets
There are various ways to represent sets using a
computer. One method is to store the elements of the set
in an unordered fashion
Assume that the universal set U is finite (and of
reasonable size so that the number of elements of U is
not larger than the memory size of the computer being
used).
First, specify an arbitrary ordering of the elements of U,
for instance a1,a2,...,an. Represent a subset A of U with
the bit string of length n, where the ith bit in this string
is 1 if ai belongs to A and is 0 if a does not belong to A.
Computer Representation of
Sets
Example: Let U ={1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, and the
ordering of elements of U has the elements in increasing
order; that is, ai = i.
– What bit strings represent
• the subset of all odd integers in U,
• the subset of all even integers in U, and
• the subset of integers not exceeding 5 in U?
Solution:
– The bit string that represents the set of odd integers in U, namely, {1, 3, 5, 7, 9}, has a one
bit in the first, third, fifth, seventh, and ninth positions, and a zero elsewhere. It is 10 1010
1010.
– Similarly, we represent the subset of all even integers in U, namely, {2, 4, 6, 8, 10}, by the
string 01 0101 0101.
– The set of all integers in U that do not exceed 5, namely, {1, 2, 3, 4, 5}, is represented by the
string 11 1110 0000.
Query???
1 2 3 4 ....
x y ( x y ) ?
1
x 1 x ?
x 1 ?
x
x( | x ) ? x y ( x y ) ?
1
1 2 3 4 .... ?
x 1 ?
1 1 1 1 1 ......... ? x