0% found this document useful (0 votes)
21 views35 pages

Lecture 3-4

Uploaded by

umar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views35 pages

Lecture 3-4

Uploaded by

umar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 35

Set Operations and

Functions
Discrete Structures
MUHAMMAD UMAR NASIR
LECTURER
FACULTY OF COMPUTING, RIPHAH INTERNATIONAL UNIVERSITY LAHORE
Union of Two Sets:

 Let A and B be sets. The union of set A and B, denoted by A ∪ B,


is the set that contains those elements that are either in A or in
B, or in both. An element x belongs to the union of the sets A and
B if and only if x belongs to A or belongs to B.
 In set builder notation union is expressed as
AUB = { x U| x A or x B}
Example: The union of set {1,3,5} and {1,2,3} is the set {1,2,3,5}
{1,3,5}U{1,2,3} = {1,2,3,5}
The union operation is commutative i.e. A∪B = B∪A.
VENN DIAGRAM FOR UNION

A ∪ B = B ∪ A that is union is commutative you


can prove this very easily only by using
definition.
MEMBERSHIP TABLE FOR
UNION
A B AUB
1 1 1
1 0 1
0 1 1
0 0 0
Intersection of Two Sets:

 Let A and B be sets. The intersection of set of set A and B,


denoted by A B, is the set that contains those elements which
are in both A and B. An element x belongs to the intersection of
the sets A and B if and only if x belongs to A and belongs to B.
 In set builder notation union is expressed as
A ∩ B = {x ∈U | x ∈ A and x ∈B}
Example: The intersection of set {1, 3, 5} and {1, 2, 3} is the set
{1, 3}
{1,3,5} {1,2,3}={1,3}
VENN DIAGRAM FOR
INTERSECTION

1- A ∩ B = B ∩ A
2- If A ∩ B = φ, then A & B are called
disjoint sets.
MEMBERSHIP TABLE FOR
INTERSECTION
A B A∩B
1 1 1
1 0 0
0 1 0
0 0 0
Disjoint Sets:

 Two sets are called disjoint if their intersection is the empty set.
 Example : Let A={1,3,5,7,9} and B={2,4,6,8}
Because A ∩ B= Null, A and B are disjoint.
Difference of Two Sets:

 Let A and B be sets. The difference of A and B, denoted by A– B,


is the set containing those elements that are in A but not in B.
The difference of A and B is also called complement of B with
respect to A.
 An element x belongs to the difference of the sets A and B if and
only if x belongs to A and x doesn’t belongs to B.
 In set builder notation union is expressed as
A – B = {x ∈U | x ∈ A and x∉B}
 Example: The difference of A= {1, 3, 5} and B= {1, 2, 3} is the
set {5}; that is
 {1, 3, 5} – {1, 2, 3} = {5}
VENN DIAGRAM FOR SET
DIFFERENCE

1- A – B ≠ B – A that is Set difference


is not commutative.
2- A – B ⊆ A
MEMBERSHIP TABLE FOR
DIFFERENCE
A B A-B
1 1 0
1 0 1
0 1 0
0 0 0
Complement of Set:

 Let U be the universal set. The complement of set A, denoted by


A ^c , is the set of those elements of U which are not present in
A. In other words, the complement of the set A is U-A. An element
is added to if and only if x ∉ A. This tells us that
A^c = {x ∈U | x ∉A}
Example: Let A = {a, e, i, o, u} (where the universal set is the set of
letters of the English alphabet)
Then A ^c= U-A ={b, c, d, f, g, h, j, k, l, m, n, p, q, r, s, t, v, w, x, y,
z}
we can express the difference of A and B as the intersection of A
and the complement of B. That is, A − B = A ∩ B ^c
VENN DIAGRAM FOR
COMPLEMENT

1. A^c = U – A
2. A ∩ A^c = φ
3. A ∪ A^c = U
MEMBERSHIP TABLE FOR
COMPLEMENT
A A^c
1 0
0 1
Principle of inclusion–
exclusion:
 The cardinality of a union of two finite sets A and B, |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,
|A ∪ B| = |A| + |B| − |A ∩ B|
 The principle of inclusion–exclusion is an important technique
used in
enumeration.
Principle of inclusion–
exclusion:
Principle of inclusion–
exclusion:
Principle of inclusion–
exclusion:
Since there are 128 ways to do Task 1 and 64 ways to do Task 2, does
this mean that there are 192 bit strings either starting with 1 or ending
with 00 ?

No, because here Task 1 and Task 2 can be done at the same time.

When we carry out Task 1 and create strings starting with 1, some of
these strings end with 00.

Therefore, we sometimes do Tasks 1 and 2 at the same time, so the sum


rule does not apply.
Principle of inclusion–
exclusion:
If we want to use the sum rule in such a case, we have to subtract the
cases when Tasks 1 and 2 are done at the same time.

How many cases are there, that is, how many strings start with 1 and end
with 00?

There is one way to pick the first bit (1),


two ways for the second, …, sixth bit (0 or 1),
one way for the seventh, eighth bit (0).

Product rule: In 25 = 32 cases, Tasks 1 and 2 are carried out at the same
time.
Principle of inclusion–
exclusion:
Since there are 128 ways to complete Task 1 and 64 ways to complete
Task 2, and in 32 of these cases Tasks 1 and 2 are completed at the same
time, there are
128 + 64 – 32 = 160 ways to do either task.

In set theory, this corresponds to sets A1 and A2 that are not disjoint. Then
we have:
|A1  A2| = |A1| + |A2| - |A1  A2|

This is called the principle of inclusion-exclusion.


Set Identities: Identity Name

A   A Identity laws
A U  A

A  U U Domination laws
A   
 There are some formulas of sets which are very important in setIdempotent laws
A  A A
theory. They are as follows. A  A A

( A)  A Complementation
laws

A  B B  A Commutative
A  B B  A laws

A  ( B  C ) ( A  B )  C Associative laws
A  ( B  C ) ( A  B )  C

A  ( B  C ) ( A  B )  ( A  C ) Distributive laws
A  ( B  C ) ( A  B )  ( A  C )

A  B A  B De Morgan’s
A  B A  B Laws

A  ( A  B)  A Absorption laws
A  ( A  B)  A

A  A U Complement laws
A  A 
Prove Equivalence by
Membership Table:
 Set identities can also be proved using membership tables. We
consider each combination of sets that an element can belong to
and verify that elements in the same combinations of sets belong
to both the sets in the identity. To indicate that an element is in a
set, a 1 is used; to indicate that an element is not in a set, a 0 is
used.
A B A B
A B AB AB A B AB

1 1 1 0 0 0 0

1 0 0 1 0 1 1

0 1 0 1 1 0 1

0 0 0 1 1 1 1
Prove by Set Builder notation
and Logical Equivalence
Prove the first De Morgan law A  B  A  B .
Solution: We can prove this identity with the following steps.
A  B = {x | x ∉ A ∩ B}
= {x | ¬ (x ∈ (A ∩ B))}
by definition of complement

= {x | ¬ (x ∈ A ∧ x ∈ B)}
by definition of does not belong symbol

= {x | ¬ (x ∈ A) ∨¬ (x ∈ B)}
by definition of intersection

= {x | x ∉ A ∨x ∉ B}
by the first De Morgan law for logical equivalences
by definition of does not belong symbol
= {x | x ∈ A ∨ x ∈ B } by definition of complement
= {x | x ∈ A U B } by definition of union
= AB by meaning of set builder notation
Function

 Let A and B be nonempty sets. A function f from A to B is an


assignment of exactly one element of B to each element of A. We
write f (a) = b if b is the unique element of B assigned by the
function f to the element a of A. If f is a function from A to B, we
write f : A → B.

Functions are sometimes also called mappings or transformations.


A function is a binary relation with following two properties.
a) The domain of binary relation is equal to set A
b) No two ordered pair in the binary relation has first same elements.
It is denoted by f : A  B while R1 , R2 and R3 is not functions.
Binary Relation:

 let A, B are two non-empty set than possible sub-sets of are called
binary relation from set A to set B.
Find all binary relations from {0,1} to {1}
 SOLUTION: Let A = {0,1} & B = {1}
 Then A × B = {(0,1), (1,1)}
 All binary relations from A to B are in fact all subsets of
 A ×B, which are:
 R 1= ∅
 R 2={(0,1)}
 R 3={(1,1)}
 R 4={(0,1), (1,1)} = A × B
Domain of a Binary Relation:

 A set consisting of first element in order pair is a domain of a


binary relation.
 Dom(R2)={0}
Co-domain of a binary
relation:
 A set consisting of second element in all order pairs in a binary
relation.
 Co-Dom(R2)={1}
 Domain of a Function:
 The first set in the Cartesian product is called domain of a
function.

 Co-domain of Function:
 Set B in the Cartesian product is called co-domain of function.

 Range of Function:
 The set of elements from co-domain which is called Range of
function.
•Domain: {1, 2, 3, 4}
•Codomain: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
•Range: {3, 5, 7, 9}
 Example: What are the domain, codomain, and range of the function
that assigns grades to students described in the next statement. Each
student in a discrete mathematics class is assigned a letter grade from
the set {A. B. C. D. F}. And suppose that the grades are A for Adams, C
for Chou, B for Goodfriend, A for Rodriguez, and F for Stevens.
 Solution: Let G be the function that assigns a grade to a student in our
discrete mathematics class.
 Domain of G is {Adams, Chou, Goodfriend, Rodriguez, Stevens}
 Codomain is the set {A, B, C, D, F}.
 Range of G is the set {A, B, C, F}
Types of Functions

One-to-One function:
 Some functions never assign the same value to two different
domain elements. These functions are said to be one-to-one or
an injunction. If and only if
x, yA (f(x) =
f(y)  x = y)
In other words: f is one-to-one if and only if it does not map two
distinct elements of A onto the same element of B.
Types of Functions

f(Linda) = Moscow g(Linda) = Moscow


f(Max) = Boston g(Max) = Boston
f(Kathy) = Hong Kong g(Kathy) = Hong
Kong
f(Peter) = Boston g(Peter) = New York
Is f one-to-one?
No, Max and Peter are Is g one-to-one?
mapped onto the same
element of the image. Yes, each element is
assigned a unique
element of the
image.
Types of Functions

Onto Function/Surjective Function:


 For some functions the range and the codomain are equal. That is,
every member of the codomain is the image of some element of
the domain. Functions with this property are called onto or
surjective functions.
 A function is called surjective function if rang.
i.e. Range (f) = co-domain (f), Range (f) = B.
Example : Let f be the function from {a, b, c, d} to {1, 2, 3} defined
by f (a) = 3, f (b) = 2, f (c) = 1, and f (d) = 3. Is f an onto function?
Solution: Because all three elements of the codomain are images of
elements in the domain, we see that f is onto. Note that if the
codomain were {1, 2, 3, 4}, then f would not be onto.
Types of Functions

Bijective Function:
A function is called bijective if it is both injective and surjective.

Example : Let f be the function from {a, b, c, d} to {1, 2, 3, 4} with f (a) = 4, f


(b) = 2, f (c) = 1, and f (d) = 3. Is f a bijection?

Solution: The function f is one-to-one and onto. It is one-to-one because no two


values in the domain are assigned the same function value. It is onto because all
four elements of the codomain are images of elements in the domain. Hence, f is
a bijection.
Types of Functions

You might also like