Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
139 views

DML Unit 3 (Sets, Functions and Relations) - Lecture Slides

This document provides an overview of key concepts in discrete mathematics and logic related to sets, functions, and relations. It defines what sets are, how to represent sets, and set operations like union, intersection, difference, and complement. It also covers functions, including one-to-one, onto, and bijective functions. Finally, it discusses concepts like subsets, cardinality, and Russell's paradox as they relate to discrete mathematics and logic.

Uploaded by

Aditya Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
139 views

DML Unit 3 (Sets, Functions and Relations) - Lecture Slides

This document provides an overview of key concepts in discrete mathematics and logic related to sets, functions, and relations. It defines what sets are, how to represent sets, and set operations like union, intersection, difference, and complement. It also covers functions, including one-to-one, onto, and bijective functions. Finally, it discusses concepts like subsets, cardinality, and Russell's paradox as they relate to discrete mathematics and logic.

Uploaded by

Aditya Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 126

Discrete Mathematics and Logic

(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}

Well known number sets:


N = {0, 1, 2, 3, ...}, the set of natural numbers
Z = {..., -2, -1, 0, 1, 2, ...}, the set of integers
Z+ = {1, 2, 3, 4, ...}, set of positive integers
Q = {p/q | p Z ; q Z and q 0} the set of rational
numbers
R the set of real numbers
C the set of complex numbers

Equality of two sets


Two sets are equal if and only if they have the same elements.
i.e., if A and B are sets, then A and B are equal if and only if
x (x A x B).
if A and B are equal sets, it can be denoted as A = B.
Eg: {a, b} = {a, b}
Eg: {1,3,5} = {3,1,5}
Eg: {1,3,3,5,5,5,5} = {1,3,5}
Eg: {1} {{1}}

Venn Diagram
Sets can be represented graphically using Venn diagrams.

Empty set / Null set


{}=
Singleton set
{ a }, { Z+ }
{}

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.

Theorem: For every set S,


1. S
2. S S
Proof of S:
Let S be a set.
S iff x(x xS).
Because the empty set contains no elements, it follows that
x is always false.
It follows that the conditional statement x xS is always
true, because the hypothesis is always false and a conditional
statement with a false hypothesis is true.
That is x(x xS) is true.
S
Its a vacuous proof.

Cardinality: If there are exactly n distinct elements in S where


n is a non-negative integer, we say that S is a finite set and
that n is the cardinality of S. The cardinality of S is denoted
by |S|.
Eg: Set S of letters in the English alphabet. Then |S| = 26.
Eg: || =0 .
A set is said to be infinite, if it is not finite.
Eg: The set of positive integers {1, 2, 3, } is infinite.
Power Set of S, P(S), is the set of all subsets of the set S.
If a set has n elements, then its power set has 2n elements.
Eg: P({0,1,2}) = {, {0}, {1}, {2}, {0,1}, {1,2}, {0,2}, {0,1,2})

The Ordered n-tuple (a1, a2, , an) is the ordered collection


that has a1 as its first element, a2 as its second element, , an
as its nth element.
Cartesian product of A and B is A X B = {(a,b) | aA bB}
Eg: A = {a, b} and B = {1, 2, 3}
A X B = {(a, 1), (a, 2), (a, 3), (b, 1), (b, 2), (b, 3)}
B X A = {(1, a), (1, b), (2, a), (2, b), (3, a), (3, b)}
AXBBXA
|A X B| = |A| * |B|

A subset R of AXB is called a relation from set A to set B.


The cartesian product of the sets A1, A2, , An, denoted by
A1XA2XXAn, is the set of ordered n-tuples (a1, a2, , an),
where ai belongs to Ai for i = 1, 2, , n.
That is, A1XA2XXAn = {(a1, a2, ..., an) | ai Ai for i
=1,2,...,n}.

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 ?

xS (P(x)) denotes the universal quantication of P(x) over


all elements in the set S.
i.e., xS (P(x)) is shorthand for x (x S P(x)).
xS (P(x)) denotes the existential quantication of P(x)
over all elements in S.
i.e., xS (P(x)) is shorthand for x (x S P(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}

Two sets are disjoint when their intersection is empty.


AB=
Eg: {1, 2 } {3, 4} =
Q: What are the resulting sets of the following.
1. {1, 2, 3} {1, 2} = {1, 2}
2. {1, 2, 3} {R, G, B} =
3. {1, 2, 3} =
4. {1, 2, 3} {1, 4} = {1, 2, 3, 4}
5. {1, 2, 3} {R, G, B} = {1, 2, 3, R, G, B}
6. {1, 2, 3} = {1, 2, 3}
7. {1, 2, 3} { } = {1, 2, 3}

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

Difference of two sets:


Difference of two sets, A - B, is set containing
elements in A but not in B.
A - B = { x | x A x B}
Eg: {1, 2 } - {3, 4} = {1, 2}
Eg: {1, 2, 3 } - {3, 4} = {1, 2}
Eg: {1, 2, 3} - {1, 2, 3} =
Eg: {1, 2, 3} - { 1, 2 } = {3}
Eg: {1, 2, 3} - { 1, 2, 3 } = { }
Eg: {1, 2, 3} - = {1, 2, 3}

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.

Q: Prove De Morgans law (A B)` = A` U B`


without using membership table.

Computer Representation of Sets:


U = { 5, 4, 3, 2, 1, 0 } = 111111
A = { 2, 1, 0 }
= 000111
B = { 3, 2 }
= 001100
AB=AvB
{ 2, 1, 0 } { 3, 2 } = {3, 2, 1, 0}
000111
{ 2, 1, 0 }
v 001100
{ 3, 2 }
001111
{3, 2, 1, 0}
AB=A^B
{ 2, 1, 0 } { 3, 2 } = { 2 }
000111
{ 2, 1, 0 }
^ 001100
{ 3, 2 }
000100
{2}

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

Domain of the function g is the set of Students.


Co-domain of the function g is the set of Grades.
Image of g(Goodfriend) is B.
Range of the function g is {A, B, C, F}
Domain of f : A B is A
Co-domain of f : A B is B
Image f( a ) = b is b
Preimage f( a ) = b is a
Range of f : A B is set of all images of elements of A

Two real-valued functions with the same domain can be


added and multiplied.
Let f1 : A R and f2 : A R
Then, (f1 + f2)(x) = f1(x) + f2(x)
(f1 f2)(x) = f1(x) f2(x)
Eg:
f1 : R R
f2 : R R
f1(x) = x2
f2(x) = x - x2
(f1 + f2)(x) = f1(x) + f2(x) = x2 + x - x2 = x
(f1 f2)(x) = f1(x) f2(x) = x2 (x - x2) = x3 - x4

Image of a subset of the domain:


f:AB
SA
Image of S under f is a subset of B.
f( S ) B
f( S ) = { x | s S ( x = f( s ) ) }

Types of functions
One-to-One (Injective) function
Onto (Surjective) function
One-to-One Correspondence (Bijective) function

One-to-One (Injective) functions:


A function is said to be One-to-one or injective, if and only if
f(a)=f(b) implies that a=b for all a and b in the domain of f.
That is, f is one-to-one iff ab ( f(a) = f(b) a = b )
That is, f is one-to-one iff ab ( a b f(a) f(b) )
Eg: A = { a, b, c, d },
B = { 1, 2, 3, 4, 5 }
g:AB
g(a) = 4,
g(b) = 5,
g(c) = 1,
g(d) = 3

Which of the following defines one-to-one function f?


ab ( a = b f(a) = f(b) )
ab ( f(a) = f(b) a = b )
ab ( a b f(a) f(b) )
ab ( f(a) = f(b) a = b )

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.

Onto (Surjective) functions:


A function f from A to B is called onto or surjective, if and only
if every element b B there is an element a A with f(a) =
b.
i.e., f is Onto function iff every b B has a A with f(a) = b.
In short, yx (f(x) = y)
Eg: A = { a, b, c, d },
B = { 1, 2, 3 }
G:AB
G(a) = 3,
G(b) = 2,
G(c) = 1,
G(d) = 3

One-to-One Correspondence (Bijection) functions:


A function is One-to-one correspondence or bijective function
if it is one-to-one and onto.
Eg: What kind relations are these (functions, one-to-one
function, onto function, one-to-one correspondence)?

Q: Diagram the following functions and mention whether they


are one-to-one, onto or one-to-one correspondence:
1. f : {a, b, c, d} {1, 2, 3, 4}
f(a) = 1
f(b) = 2
f(c) = 3
f(d) = 4
2. g : {a, b, c, d} {1, 2, 3, 4}
g(a) = 1
g(b) = 1
g(c) = 4
g(d) = 4

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}

Eg: Set A = {a, b, c, d}


Relation R = {(a, d), (a, b), (b, b), (b, d), (c, b), (c, a), (d, b)}

Eg: Set A = {1, 2, 3, 4}


Relation R = ?

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)}

Properties of Relations on a set:


1. Reflexive
2. Symmetric
3. Antisymmetric
4. Transitive

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

Q: Mention the properties (reflexive, symmetric, antisymmetric


and transitive properties) of the relations.
1. Relation of {a, b, c},
R = {(a, a), (b, b), (c, c), (b, c), (c, b)}
Ans:
2. Relation of {a, b, c, d},
S = {(a, c), (c, a), (a, d), (d, a), (d, d), (a, b), (b, a), (b, b)}
Ans:

Q: Mention the properties (reflexive, symmetric, antisymmetric


and transitive properties) of the relations.
1. Relation of {a, b, c},
R = {(a, a), (b, b), (c, c), (b, c), (c, b)}
Ans: Y, Y, N, Y
2. Relation of {a, b, c, d},
S = {(a, c), (c, a), (a, d), (d, a), (d, d), (a, b), (b, a), (b, b)}
Ans: N, Y, N, N

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.

Powers of a relation R on a set: Rn


The powers of relation R for n=1, 2, 3, ... are defined by:
R1 = R
Rn+1 = Rn R, where n > 0
Eg:
R = {(1, 1), (2, 1), (3, 2), (4, 3)}
R2 = RR
R2 = {(1, 1), (2, 1), (3, 1), (4, 2)}
R3 = R2R
R3 = {(1, 1), (2, 1), (3, 1), (4, 1)}
R4 = R3R
R4 = {(1, 1), (2, 1), (3, 1), (4, 1)}

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)}

Q: Let A = {1, 2, 3, 4} and


R = {(1,1), (1,2), (2,1), (2,2), (3,4), (4,3), (3,3), (4,4)}
be a relation on A. Verify that R is an equivalence relation.
Soln:
R is reflexive since it contains (1,1), (2,2), (3,3) and (4,4).
That is, x (x,x)R
R is symmetric since it contains (1,2), (2,1), (3,4), (4,3) and no
(a,b) where (b,a) is not in R.
That is, xy ((x,y)R (y,x)R)
R is transitive since for every pair of (x,y) and (y,z), there is
(x,z) in R.
That is, xyz ((x,y)R (y,z)R (x,z)R)
Therefore, R is an equivalence relation.

Q: Let R be a relation on the set of real numbers such that aRb


iff a-b is an integer. Prove whether R is an equivalence relation.
Soln:

Q: Let R be a relation on the set of real numbers such that aRb


iff a-b is an integer. Prove whether R is an equivalence relation.
Soln: a-a=0 and 0Z
That is, a (aRa).
R is reflexive.
Let a-b = k be an integer.
Then, b-a = -k, which is also an integer.
That is, if aRb, then bRa.
R is symmetric.
Let a-b=k and b-c=m where k and m are integers.
Then, a-c = (a-b)-(c-b) = k-(-m), which is an integer.
That is, if aRb and bRc, then aRc.
R is transitive.
Because R is reflexive, symmetric and transitive,
R is an equivalence relation.

Q: Let a and b be integers and m be a positive integer with


m>1. Show that the relation R = { (a, b) | a b (mod m) }
is an equivalence relation on the set of integers.
Soln:

Q: Let a and b be integers and m be a positive integer with


m>1. Show that the relation R = { (a, b) | a b (mod m) }
is an equivalence relation on the set of integers.
Soln:
If a b (mod m), then m|(a-b) (read: m divides a-b)
a a (mod m) because m|a-a, which is same as m|0.
R is reflexive.
Let a b (mod m)
i.e., m | (a-b)
mk = a-b, where k is an integer
m(-k) = b-a
i.e., b a (mod m) because -k is also an integer
R is symmetric.

Q: Let a and b be integers and m be a positive integer with


m>1. Show that the relation R = { (a, b) | a b (mod m) }
is an equivalence relation on the set of integers.
Soln:

Let a b (mod m) and b c (mod m)


i.e., mk = a-b and ml = b-c, where k and l are integers.
mk+ml = a-b+b-c
m(k+l) = a-c
i.e., a c (mod m)
R is transitive.
R is reflexive, symmetric and transitive.
R is an equivalence relation.

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 .

Q: What are the equivalence classes of 0 and 1 for the


congruence modulo 10?
Soln:
The equivalence class of 0 contains all integers a such that
a 0 (mod 10).
[0] = { , -20, -10, 0, 10, 20, }
Similarly, the equivalence class of 1 contains all integers a
such that a 1 (mod 10).
[1] = { , -19, -9, 1, 11, 21, }
Congruence classes modulo m: are the equivalence
classes of the relation congruence modulo m.
[a]m = { , a-2m, a-m, a, a+m, a+2m, }

Q: What is the equivalence class of an integer a for the


equivalence relation R defined by
aRb iff a = b or a = -b?
Soln:
aRb iff a = b or a = -b means a related itself and
negative of itself.
That is, [a]R = {a, -a}
For example, [10]R = {10, -10}
[-100]R = {100, -100}
[0]R = {0}

Theorem: Let R be an equivalence relation on a set A.


These statements for elements a and b of A are equivalent:
(i) aRb
(ii) [a] = [b] (iii) [a][b]
Note:
1. Two equivalence classes are either disjoint or identical.
2. Let R be an equivalence relation on a set A and let a,bA.
If [a] [b] then [a][b] = .
3. For a,bA, if b[a] then [a] = [b].

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

The set P = {A1, A2, , An} is called the partition of A.

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.

Q: Show that (Z+, |) is a Poset. (Its the divisibility relation)


Soln: a|a for every integer a.
| is Reflexive
Whenever ab, at least one of a|b or b|a is false.
| is antisymmetric.
Whenever a|b and b|c, a|c.
| is transitive.
(Z, |) is a Poset.

Q: Show that (P(S), ) is a Poset.


Soln:

Comparable and Incomparable:


Elements a and b are incomparable when they are elements
of a poset (S, ) such that neither ab nor ba.
Eg: In poset (Z+, ), for every pair (a,b) either aRb or bRa. For
instance, 1020. That is, every pair (a,b) is comparable.
Eg: In poset (Z+, |), 5 and 7 are incomparable because 5|7 is
false and 7|5 is false. Whereas 6 and 18 are comparable
because 6 divides 18.
Total Ordering (Linear Ordering):
Every pair of elements in S are comparable.
Eg: (Z, )

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 and Minimal elements:


a is a maximal in the poset (S, ) if there is no bS such that ab.
a is a minimal in the poset (S, ) if there is no bS such that ba.
Greatest and Least elements:
a is the greatest element of the poset (S, ) if ba for all bS.
a is the least element of the poset (S, ) if ab for all bS.
Upper Bound and Lower Bound elements:
If u is an element of S such that au for all elements aA, then u is
an upper bound of A.
If l is an element of S such that la for all elements aA, then l is a
lower bound of A.
Least Upper Bound and Greatest Lower Bound elements:
x is an upper bound that is less than every other upper bound of A.
l is a lower bound that is greater than every other lower bound of A.

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

Eg: Poset ({1,2,...,24}, |). Its a divides relation.

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:

Eg: Poset ({1,2,...,24}, |). Its a divides relation.

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

Eg: Let S = Power set of {a,b,c}. Poset (S, ).


Maximal elements:
Minimal elements:
Greatest element:
Least element:
For the subset A = {ab,b},
Upper bound of A:
Lower bound of A:
Least Upper bound of A:
Greatest Lower bound of A:

Eg: Let S = Power set of {a,b,c}. Poset (S, ).


Maximal elements: abc
Minimal elements:
Greatest element: abc
Least element:
For the subset A = {ab,b},
Upper bound of A: ab, abc
Lower bound of A: b,
Least Upper bound of A: ab
Greatest Lower bound of A: b

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: g,h,i


Minimal elements: a,b,c,e
Greatest element: None
Least element: None
For the subset A={d,e,f}
Upper bound of A: None
Lower bound of A: None
Least Upper bound of A: None
Greatest Lower bound of A: None
For the subset A={b,d}
Upper bound of A: d,g
Lower bound of A: b
Least Upper bound of A: d
Greatest Lower bound of A: b

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: b,d,i,j


Minimal elements: a
Greatest element: None
Least element: a
For the subset A={c,e}
Upper bound of A: e,f,g,h,i,j
Lower bound of A: c,a
Least Upper bound of A: e
Greatest Lower bound of A: c
For the subset be A={b,i}
Upper bound of A: None
Lower bound of A: a
Least Upper bound of A: None
Greatest Lower bound of A: 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.

Topological Sorting: Constructing a compatible total


ordering from a partial ordering is called topological sorting.
What makes the total ordering compatible with a partial
ordering?
If (a,b)R, then ab is in the total ordering.
If a and b are not comparable, then it is either ab or ba in the
total ordering.

Lemma: Every finite nonempty poset (S, ) has at least one


minimal element.
Topological Sorting Algorithm:

Q: Find a compatible total ordering for the poset


({1, 2, 4, 5, 12, 20}, |).
Soln:

Q: Let S be Power set of {a,b,c}.


Find a compatible total ordering for the poset (S, ).
Soln:

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.

Q: Let {an} be a sequence that satisfies the


recurrence relation an = an-1 - an-2 for n = 2, 3, , and
suppose that a0 = 3 and a1 = 5. What are a2 and a5?
Ans:
a2 = 5 - 3 = 2
a3 = 2 - 5 = -3
a4 = -3 - 2 = -5
a5 = -5 - (-3) = -2

Q: Determine whether the sequence {an}, where an =


3n for every nonnegative integer n, is a solution of the
recurrence relation an = 2an-1 - an-2 for n = 2, 3, 4, .
Answer the same question where an = 2n and
where an = 5.
Ans:
(a) True because 2(3(n-1))-3(n-2) = 3n
(b) False because 2(2n-1)-2n-2 = 2n is false.
(c) True because 2(5) - 5 = 5.

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.

Ans: an = an-1 + an-2, where a1 = 2 and a2 = 3.


2, 3, 5, 8, 13, 21, 34, 55.
55 bit strings of length 8 dont have 2 consecutive 0s.

The Tower of Hanoi puzzle:


Move n disks from peg A to peg B using peg C.
Move top n-1 disk from peg A to C.
Move disk# n from peg A to B.
Move n-1 disks from peg C to B
# of moves, Hn=2Hn-1+1 with the initial condition
H1=1.
Power(x, y) = x * Power(x, y-1), where xR, yZ+
with the initial condition Power(x, 0) = 1.
Factorial(n) = n * Factorial(n-1),
where nZ+ and Factorial(0) = 1.

Q: Suppose that a person deposits Rs. 10,000 in a


savings account at a bank yielding 11% per annum
with interest compounded annually. How much will be
in the account after 30 years?
Pn = Pn-1 + 0.11*Pn-1, P0 = 10,000
P30 = 228,922

Solving Recurrence Relations


Finding solution to a recurrence relation means finding
closed form expressions.
Often in computer science, it means to find a way of
evaluating an expression in constant time instead
evaluating recursively in the order of a non-constant
function of n.
Q: Solve an = an-1 + C, where a0 is a constant
Solution: an = C*n + a0
Q: Solve an = Can-1, where a0 is a constant
Solution: an = Cn * a0

Solving Linear Homogeneous Recurrence


Relations with Constant Coefficients
Linear homogeneous recurrence relation of degree k
with constant coefficients is a recurrence relation of
the form:
an = c1an-1 + c2an-2 + ... + ckan-k
where c1, c2, c3, ..., ck are reals and ck 0.

an = c1an-1 + c2an-2 + ... + ckan-k


an = 2an-1 + 3 is not homogeneous (not all terms
has a factor aj)
an = nan-1 coefficient not constant
an = 3a2n-1 is not linear
an = an-1 + an-2 is of degree 2
an = 4an-2 is of degree 2
an = 3an-5 - 4an-2 is of degree 5

Linear Homogenous Recurrence Relation with constant


coefficients occur often in modeling problems and
can be systematically solved.
Theorem 1 - For degree 2 and distinct roots r1 and r2
{an} is a solution of an = c1an-1 + c2an-2
iff an = 1r1n + 2r2n for n = 0, 1, 2, ...,
where r2 - c1r - c2 = 0 has two distinct roots r1 and r2,
with constants 1 and 2.

{an} is a solution of an = c1an-1 + c2an-2


iff an = 1r1n + 2r2n for n = 0, 1, 2, ...,
where r2 - c1r - c2 = 0 has two distinct roots r1 and r2,
with constants 1 and 2
Recurrence: an = c1an-1 + c2an-2
Characteristic equation: r2 - c1r - c2 = 0
Characteristic roots: r1 and r2 (distinct roots)
Solution for the recurrence: an = 1r1n + 2r2n for n = 0,1,2,...,
Constants: 1 and 1 are constants, which can be
found using initial conditions a0 and a1.

Q: What is the solution (closed form) of


an = an-1+ 2an-2 where a0 = 2, a1 = 7
Soln: c1= 1, c2 = 2
r2 - c1r - c2 = 0 is the characteristic equation
r2 - r - 2 = (r+1)(r-2) = 0
r1 = 2, r2 = -1 are the characteristic roots
Using initial conditions and roots, solve
an = 1r1n + 2r2n for 1 and 2
an = 12n + 2(-1)n

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

Solving simultaneous equations


1 + 2 = 2
21 - 2 = 7
1 =3, 2 = -1
an = 12n + 2(-1)n
an = 3*2n + (-1)n+1
is the solution (closed form) for
an = an-1+ 2an-2 where a0 = 2, a1 = 7

Q: Find the solution (closed form) of an = 7an-1 - 10an-2


where a0 = 2, a1 = 1
Soln:

Q: Find the solution (closed form) of fn = fn-1 + fn-2


where f0 = 0, f1 = 1
Soln:

Q: Find the solution (closed form) of an = 2an-1


where a0 = 3
Soln:
(Hint: its of degree 1, and its of a known form)

Q: Find the solution (closed form) of an = 2an-1


where a0 = 3
Soln: This is a known form.
The solution of an = Can-1 would be a0 * Cn
Therefore, solution of an = 2an-1 is 3 * 2n
Alternate Soln: By substitution.

Q: Find the solution (closed form) of an = 2an-1


where a0 = 3
Soln: By substitution
an = 2an-1 where a0 = 3
an = 2an-1
= 2(2an-2) = 22an-2
= 22(2an-3) = 23an-3
= 2i an-i
When n-i=0, i=n
= 2 n a0
= 3*2n

Soln: By the theorem 1 with degree 2.


The recurrence relation and initial conditions
an = 2an-1
= 2an-1 + 0an-2 for n 1
Its of the form an = c1an-1 + c2an-2 as in the theorem
for degree 2.
a0 = 3
c1= 2, c2 = 0
Determine if there are two distinct roots, r1 and r2.
r 2 - c 1r - c 2 = 0
r2 - 2r - 0 = (r-2)(r+0) = 0
r1 = 2
r2 = 0

Using initial conditions and roots, solve


an = 1r1n + 2r2n for constants 1 and 2
a n = 12 n + 20 n
1 + 2 = 3
21 = 6
1 = 3, 2 = 0
a n = 1 r1 n + 2 r2 n
= 3*2n + (0)0n
= 3*2n is the solution for an = 2an-1 where a0 = 3

Q: What is the solution (closed form) of


an = 6an-1- 9an-2 where a0 = 1, a1 = 6
Soln: c1= 6, c2 = -9
r2 - 6r + 9 = (r-3)(r-3) = 0
r1 = 3, r2 = 3
but the roots are not distinct

Theorem 2 - For degree 2 and 1 root (multiplicity 2)


{an} is a solution of an = c1an-1 + c2an-2
iff an = 1r0n + 2nr0n for n=0,1,2,...,
where r2 - c1r - c2 = 0 has one root r0,
with constants 1 and 2.

Q: What is the solution (closed form) of


an = 6an-1- 9an-2 where a0 = 1, a1 = 6
Soln: c1= 6, c2 = -9
r2 - 6r + 9 = (r-3)(r-3) = 0
r0 = 3
an = 1r0n + 2nr0n = 13n + 2n3n
for constants 1 and 2
an = 1r0n + 2nr0n
= 13n + 2n3n
= 3n + n3n

Theorem 3 - For degree k and distinct roots


{an} is a solution of an = c1an-1 + c2an-2+ .. +ckan-k
iff an = 1r1n + 2r2n + .. + krkn for n=0, 1, 2, ...,
where rk - c1rk-1 - .. - ck = 0 has k distinct roots
r1, r2, .. rk, with constants 1, 2, .. , k

Q: What is the solution (closed form) of


an = 6an-1- 11an-2 + 6an-3 where a0 = 2, a1 = 5, a2 =
15

Soln:

Q: What is the solution (closed form) of


an = -3an-1- 3an-2 - an-3 where a0 = 1, a1 = -2, a2 = -1
Soln:

<Thank You />

You might also like