DML Unit 3 (Sets, Functions and Relations) - Lecture Slides
DML Unit 3 (Sets, Functions and Relations) - Lecture Slides
(UE15CS205)
Unit 3 - Sets, Functions and Relations
Mr. Channa Bankapur
channabankapur {@pes.edu, @gmail.com}
Sets
Sets are discrete structures used to group objects together
(often the objects having similar properties).
A set is an unordered collection of objects.
The objects in a set are called the elements or members
of the set.
A set is said to contain its elements.
An element is said to belong to the set.
a S denotes that a is an element of the set S.
a S denotes that a is not an element of the set S.
Set roster form: All the members of the set are listed
separated by commas enclosed in curly braces.
Eg: A set of natural numbers from 1 to 5.
S = {1, 2, 3, 4, 5}
Eg: the set of positive integers less than hundred
S = {1, 2, 3, , 99}
Set builder form: Elements in the set are characterized by
stating the property or properties they must have to be
members.
Eg: the set of positive integers less than hundred
A = { x Z+ | x < 100}
Eg: set of rational numbers.
B = { p/q | p Z; q Z, and q 0}
Venn Diagram
Sets can be represented graphically using Venn diagrams.
Subsets:
The set A is called a subset of set B if and only if every
element of A is also an element of B.
We use the notation A B to indicate that A is a subset of
set B.
A B if and only if x (x A x B) is true.
Proper Subset:
When set A is a subset of set B but A B, we write A B
and say that A is a proper subset of B.
For A B to be true it must be the case that A B and
there must exist an element x of B that is not an element
of A.
That is, A is a proper subset of B if
x (xA xB) x (xB xA) is true.
Truth Sets
Given Predicate P, and domain D, the truth set of P is the set
of elements x in D for which P(x) is true.
The truth set of P(x) is denoted by {x D | P(x)}.
Q: What are the truth sets of the predicates P(x), Q(x), and
R(x), where the domain is the set of integers and
P(x) is |x| = 1,
Q(x) is x2 = 2, and
R(x) is |x| = x ?
Russells Paradox
Let the domain be the set of all sets
S = {x | xx}
Is S a member of itself?
Suppose, SS. Then, the predicate xx is false. Hence, S
should not belong to S. Its a contradiction.
Suppose, SS. Then, the predicate xx is true. Hence, S
should belong to S. Its a contradiction.
Therefore, it is a paradox.
Analogy: (Credit: Krithika, PES-CSE 2014-17)
Predicate: I help people who cant help themselves.
Suppose Im one of those people.
When Im sick (i.e. I cant help myself), Im in a paradox.
According to the predicate, I should help me, but I cant do
that because Im sick. If I dont help myself, Im violating the
predicate.
Russells Paradox
The Big Bang Theory Scene: Leonards car. Play that
funky music, white boy is playing on the stereo.
Sheldon: So theyre requesting that the white boy play the
funky music, yes?
Leonard: Yes.
Sheldon: And this music were listening to right now is
funky as well?
Leonard: Sure.
Sheldon: Let me ask you this. Do you think this song is the
music the white boy ultimately plays?
Leonard: It could be.
Sheldon: So its like the musical equivalent of Russells
Paradox, the question of whether the set of all sets that
dont contain themselves as members contains itself?
Leonard: Exactly.
Sheldon: Well then I hate it. Music should just be fun.
Set Operations
Union of sets A and B contains those elements in A, B or both.
A B = { x | x A x B}
Intersection of sets A and B contains those elements in both
A and B.
A B = { x | x A x B}
Cardinality of union:
If sets A and B are disjoint,
|A B| = |A| + |B|
In general,
|A B| = |A| + |B| - |A B|
Generalization of this result (of n sets) is called the
principle of inclusion-exclusion.
Eg: A = {1, 2, 3}, B = {3, 4}
|A B| = |A| + |B| - |A B| = 3+2-1 = 4
Eg: | {1, 2, 3} { 2, 3, 4 } | = 3+3-2 = 4
Complement of a set:
Complement, (A bar) or A`, is the complement
with respect to the universal set, U. That is, the
difference U - A is the complement of A.
= { x | x U x A}
= { x | x A}
Eg: U = { 1, 2, 3, 4, 5, 6 }
A = { 1, 2, 3, 4 }
= { 5, 6}
Eg: U = {a, e, i, o, u }
A = {a, e, o }
= {i, u}
Membership Tables
(Observe the similarities with the Truth Tables)
Eg: Use a membership table to show
A(BC) = (AB) (AC)
Membership Table
Prove De Morgans law (A U B)` = A` B`
using membership table.
Functions
Function f from A to B is assignment of exactly one element
of B to each element of A. f(a) = b where b is an element of
B assigned by f to the element a of A.
f:AB
Functions also called mappings or transformations.
Eg: g : Students Grades
Types of functions
One-to-One (Injective) function
Onto (Surjective) function
One-to-One Correspondence (Bijective) function
Increasing/Decreasing functions:
Consider a function f whose domain and codomain are
subsets of the set of real numbers.
Function f is increasing if f(x) f(y) for real x < y
That is, xy( x < y f(x) f(y) )
Function f is strictly increasing if f(x) < f(y) for real x < y.
That is, xy( x < y f(x) < f(y) )
Strictly increasing functions must be one-to-one.
Function f is decreasing if f(x) f(y) for real x < y.
That is, xy( x < y f(x) f(y) )
Function f is strictly decreasing if f(x) > f(y) for real x < y.
That is, xy( x < y f(x) > f(y) )
Strictly decreasing functions must be one-to-one.
Inverse Function:
Inverse of a function f from A to B such that
f-1(b) = a when f(a) = b.
Function f is invertible when f is one-to-one correspondence
(i.e. one-to-one and onto), otherwise inverse function of f does
not exists.
Eg: f : R+R+
f(x) = x2
f-1(x) = x1/2
f( 3 ) = 32 = 9
f-1(9) = 91/2 = 3
Eg: f : ZZ
f(x) = x + 3
f-1(x) = x - 3
f( 20 ) = 23
f-1(23) = 20
Composition of Functions:
Composition of function g from A to B and function f from B to C.
(f g) (a) = f( g( a ) )
Eg:
f(x) = 5x + 7
g(x) = 3x + 2
(f g) (x) = f( g(x) ) = f(3x+2) = 5(3x+2) + 7 = 15x + 17
(g f) (x) = g( f(x) ) = g(5x+7) = 3(5x+7) + 2 = 15x + 23
(f g) (x) (g f) (x)
Relations
A binary relation from A to B is a subset of AXB.
Element a is related to b by R is denoted by aRb.
aRb denotes (a, b) R
ab denotes (a, b) R
Eg:
A = {0, 1, 2}
B = {a, b}
A x B = { (0, a), (1, a), (0, b), (1, b), (2, a), (2, b) }
R = { (0, a), (1, a), (0, b), (2, b) } A x B
Relations on a Set:
Relation on the set A is a relation from A to A.
Eg: A = {1,2,3,4}
A x A = { (1,1), (1,2), (1,3), (1,4),
(2,1), (2,2), (2,3), (2,4),
(3,1), (3,2), (3,3), (3,4),
(4,1), (4,2), (4,3), (4,4) }
R = { (a, b) | a divides b}
= {(1,1), (1,2), (1,3), (1,4),
(2,2), (2,4), (3,3), (4,4)}
R1 = {(a, b) | a >= b}
R2 = {(a, b) | a = b}
Example relations:
Relation R on the set of integers such that aRb if and only if
a = b or a = -b.
Relation R on the set of real numbers such that aRb if and
only if a - b is an integer.
Relation R = {(a, b) | a b (mod 10)}.
[Replace 10 with m where it is a positive integer with m>1]
Relation R on the set of strings of English letters such that
aRb if and only if l(a) = l(b), where l(x) is the length of the
string x.
Let A = {1, 2, 3, 4}. Relation R on set A be {(1,1), (1,2),
(2,1), (2,2), (3,4), (4,3), (3,3), (4,4)}.
Let S = {a,b,c,d,e,f}. Relation R on set S be {(a,a),(b,b),
(b,c),(c,b),(c,c),(d,d),(d,e),(d,f),(e,d),(e,e),(e,f),(f,d),(f,e),(f,f)}
Reflexive Relations:
A relation R on a set A is reflexive iff
(a,a)R for every element aA.
aA ((a, a) R).
Eg: A = {1, 2, 3, 4}
R = {(1, 1), (2, 2), (3, 3), (4, 4), (1, 2)} is reflexive
1
2
3
4
1
1
0
0
0
2
1
1
0
0
3
0
0
1
0
4
0
0
0
1
Symmetric Relations:
A relation R on a set A is symmetric iff
(b,a)R whenever (a,b)R, for all a,bA.
aA bA ((a, b)R (b, a)R)
aA bA ((a, b)R (b, a)R)
Eg: Let set A = {1, 2, 3, 4}
R = {(1, 2), (2, 1), (1, 4), (4, 1), (3, 3)} symmetric
1
2
3
4
1
0
1
0
1
2
1
0
0
0
3
0
0
1
0
4
1
0
0
0
Antisymmetric Relations:
A relation R on a set A is antisymmetric iff
a=b whenever (a,b)R and (b,a)R, for all a,bR.
aA bA ((a,b)R (b,a)R a=b)
aA bA ((a b) (a, b)R (b, a)R )
Eg: Let set A = {1, 2, 3, 4}
R = {(1, 2), (3, 3), (4, 1)} antisymmetric
1
2
3
4
1
0
0
0
1
2
1
0
0
0
3
0
0
1
0
4
0
0
0
0
Symmetric? Antisymmetric?
1 2 3
1 2
1 0 1 1
1 0 1
2 1 0 0
2 0 0
3 1 0 1
3 1 0
3
1
0
1
1
1 0
2 0
3 0
2
1
0
1
3
1
0
1
1
1 0
2 0
3 0
2
0
0
0
3
0
0
1
1
1 0
2 0
3 0
2
1
0
0
3
0
0
1
1
1 0
2 0
3 0
2
0
0
0
3
0
0
0
Symmetric? Antisymmetric?
1 2 3
1 2
1 0 1 1
1 0 1
2 1 0 0
2 0 0
3 1 0 1 Y N
3 1 0
3
1
0
1 N N
1
1 0
2 0
3 0
2
1
0
1
3
1
0
1 N Y
1
1 0
2 0
3 0
2
0
0
0
3
0
0
1 Y Y
1
1 0
2 0
3 0
2
1
0
0
3
0
0
1 N Y
1
1 0
2 0
3 0
2
0
0
0
3
0
0
0 Y Y
Transitive Relations:
A relation R on a set A is transitive iff
(a,c)R whenever (a,b)R and (b,c)R, for all a,b,cR.
aA bA cA ((a,b)R (b,c)R (a,c)
R)
1
2
3
4
1
0
0
0
0
2
1
0
0
0
3
1
1
1
1
4
1
1
0
0
1
2
3
4
1
1
0
1
0
2
0
0
0
0
3
1
0
1
0
4
0
0
0
0
Relation
Reflexive
Symmetric
Antisymmetric
Transitive
Relation
Reflexive
Symmetric
Antisymmetric
Transitive
Combining Relations:
Relations from A to B are subsets of A x B and can be
combined in any way two sets can be combined.
Eg: A = {0, 1, 2}, B = {a, b}
A x B = { (0, a), (1, a), (0, b), (1, b), (2, a), (2, b) }
R1 = {(0, a), (0, b)}, R2 = {(0, b), (1, a), (1, b)}
R1 R2 = {(0, b)}
R1 U R2 = {(0, a), (0, b), (1, a), (1, b)}
R1 - R2 = {(0, a)}
R2 - R1 = {(1, a), (1, b)}
R1 R2 = R1 U R2 - R1 R2
= {(0, a), (0, b), (1, a), (1, b)} - {(0,b)}
= {(0, a), (1, a), (1, b)}
Composite Relations: S R
if (a, b)R (b, c)S, then (a, c) S R
Eg:
A = {0, 1, 2}, B = {a, b}, C = {X, Y, Z}
Relation from A to B: R = {(0, a), (1, b), (2, b)}
Relation from B to C: S = {(a, X), (b, Y), (a, Z)}
S R = {(0,X), (0,Z), (1,Y), (2,Y)}
R S does not exists because co-domain of S is different
from domain of R.
Equivalence Relations:
A relation R on a set A is called an equivalence relation if it is
reflexive, symmetric, and transitive.
Eg: Let S = {a,b,c,d,e,f}. Relation R on set S be {(a,a),(b,b),
(b,c),(c,b),(c,c),(d,d),(d,e),(d,f),(e,d),(e,e),(e,f),(f,d),(f,e),(f,f)}
Equivalence Classes:
Let R be an equivalence relation on a set A. The set of all the
elements that are related to an element a of A is called
equivalence class of a denoted by [a]R or [a] when the
relation is implicit.
i.e. [a]R = {s | (a,s) R}
Elements of [a]R
are also known as
representatives of [a]R .
Partition of a Set:
Let A be a nonempty set. Let P be a set of nonempty subsets
A1, A2, , An of the set A such that
Ai Aj = for ij
A1 A 2 A n = A
Mutually Exclusive
Collectively exhaustive
Partial Orderings
Partial Order:
A relation R on the set S is called a partial order/ordering if it
is reflexive, antisymmetric and transitive.
Poset (S, R):
Relation R is a partial ordering on set S.
Eg: (Z, ) is a Poset.
Eg: (Z+, |) is a Poset.
(S, ):
(S, ) is notation for poset where relation is a partial ordering
on set S.
Hasse Diagram:
In a digraph of a Partial Order,
1. remove self-loops because we know the partial order is
reflexive.
2. remove direction
marks from edges
because we know that
the edges always
point upwards as the
relation is antisymmetric.
3. remove transitive edges because we know the relation is
transitive. If there are edges (a,b) and (b,c), remove (a,c).
Maximal elements:12
Minimal elements: 1
Greatest element: 12
Least element: 1
These above ones
are defined on the poset.
The following are defined on a subset of the poset.
Let the subset be A= {2,3}
Upper bound of A: 12
Lower bound of A: 1
Least Upper bound of A: 12
Greatest Lower bound of A: 1
Maximal elements:
Minimal elements:
Greatest element:
Least element:
For the subset A = {2,3},
Upper bound of A:
Lower bound of A:
Least Upper bound of A:
Greatest Lower bound of A:
For the subset A = {6,10}
Upper bound of A:
Lower bound of A:
Least Upper bound of A:
Greatest Lower bound of A:
Maximal elements: 24, 16, 18, 20, 22, 15, 14, 21, 19, 17, 13, 23
Minimal elements: 1
Greatest element: None
Least element: 1
For the subset A = {2,3},
Upper bound of A: 6, 12, 18, 24
Lower bound of A: 1
Least Upper bound of A: 6
Greatest Lower bound of A: 1
For the subset A = {6,10}
Upper bound of A: None
Lower bound of A: 2, 1
Least Upper bound of A: None
Greatest Lower bound of A: 2
Maximal elements:
Minimal elements:
Greatest element:
Least element:
For the subset A={d,e,f}
Upper bound of A:
Lower bound of A:
Least Upper bound of A:
Greatest Lower bound of A:
For the subset A={b,d}
Upper bound of A:
Lower bound of A:
Least Upper bound of A:
Greatest Lower bound of A:
Maximal elements:
Minimal elements:
Greatest element:
Least element:
For the subset A={c,e}
Upper bound of A:
Lower bound of A:
Least Upper bound of A:
Greatest Lower bound of A:
For the subset be A={b,i}
Upper bound of A:
Lower bound of A:
Least Upper bound of A:
Greatest Lower bound of A:
Maximal elements: f
Minimal elements: a
Greatest element: f
Least element: a
For the subset A={b, c}
Upper bound of A: d,e,f
Lower bound of A: a
Least Upper bound of A: None
Greatest Lower bound of A: a
Note: The above example demonstrates, having multiple
upper bounds for a pair of elements doesnt guarantee to have
a least upper bound.
Lattice:
A partially ordered set in which every pair of elements has
both a least upper bound and greatest lower bound is
called a lattice.
Eg: Poset (Z+, |)
Lattice:
A partially ordered set in which every pair of elements has
both a least upper bound and
greatest lower bound
is called a lattice.
Eg: How many functions are there from a set with m elements
to a set with n elements?
Ans: n * n * n (m times) = nm
Eg: How many one-to-one functions are there from a set with
m elements to a set with n elements?
Ans: n * (n - 1) * (n - 2) * * (n - m + 1),
where m n
Eg: How many onto functions (n m)
Ans:
98
Recurrence Relations
A recurrence relation for the sequence {an} is an
equation that expresses an in terms of one or more of
the previous terms of the sequence, namely, a0, a1, ,
an-1, for all integers n with n n0, where n0 is a
nonnegative integer.
A sequence is called a solution of a recurrence relation
if its terms satisfy the recurrence relation.
Fibonacci numbers:
fn = fn-1 + fn-2, where f1 = 1 and f2 = 1.
Eg: Find a recurrence relation and give initial
conditions for the number of bit strings of length n
that do not have two consecutive 0s. How many such
bit strings are there of length eight.
an = 12n + 2(-1)n
for constants 1 and 2
a0 = 2
= 1 r1 0 + 2 r2 0
= 120 + 2(-1)0
= 1 + 2
1 + 2 = 2
a1 = 7
= 1 r1 1 + 2 r2 1
= 121 + 2(-1)1
= 21 - 2
21 - 2 = 7
Soln: