Download presentation
Presentation is loading. Please wait.
Published byEmily Hardy Modified over 9 years ago
1
Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
2
Cartesian products The Cartesian product of set A and set B is denoted by A B and equals {(a, b) a A and b B}. The elements of A B are ordered pairs. The elements of A 1 A 2 … A n are ordered n-tuples. A B = A B
3
Ex. A={2, 3, 4}, B={4, 5}, C={x,y} A B ={,,,,, }
4
Tree diagrams for the Cartesian product
5
Relations Any subsets of A B is called a binary relation from A to B. Any subset of A A is called a binary relation on A. For finite sets A and B with A =m and B =n, there are 2 mn relations from A to B.
6
Example: Let A = {1, 2, 3, 4}. Which ordered pairs are in the relation R = {(a, b) | a < b} ? Solution: R = { Domain= set of first elements in the caresian product. Range= set of second elements in the caresian product. Domain={1,2,3} Range={2,3,4} (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)}
7
Converse of a Relation A is given by the relation à such that the elements in the ordered pairs in A are interchanged. i.e if xAy then y à x.
8
Matrix Representation of a Relation M R = [m ij ] (where i=row, j=col) m ij ={1 iff (i,j) R and 0 iff (i,j) R} Ex: R : {1,2,3} {1,2} where x > y – R = {(2,1),(3,1),(3,2)}
10
Graph Representation of a Relation
11
Properties of Relations A relation R on a set A is called reflexive if (a, a) R for every element a A. A relation on a set A is called irreflexive if (a, a) R for every element a A.
12
A relation R on a set A is called symmetric if (b, a) R whenever (a, b) R for all a, b A. A relation R on a set A is called antisymmetric if a = b whenever (a, b) R and (b, a) R. A relation R on a set A is called asymmetric if (a, b) R implies that (b, a) R for all a,b A.
13
A relation R on a set A is called transitive if whenever (a, b) R and (b, c) R, then (a, c) R for a, b, c A.
14
A={1,2,3,4,5,6,7,8,9} Give examples of relation R, such that, I.R is not reflexive and not irreflexive. II.R is symmetric as well as antisymmetric. III.R is transitive but not symmetric and not reflexive. IV.R is transitive, reflexive but not symmetric.
15
Equivalence Relations Any binary relation that is: Reflexive Symmetric Transitive
16
Equivalence Classes Let R be an equivalence relation on a set A. The set of all elements that are related to an element a of A is called the equivalence class of a. The equivalence class of a with respect to R is denoted by [a] R. If b [a] R, b is called a representative of this equivalence class.
17
Partition A partition of a set S is a collection of disjoint nonempty subsets of S that have S as their union. In other words, the collection of subsets A i, i I, forms a partition of S if and only if (i) A i for i I A i A j = , if i j i I A i = S
18
Let R be an equivalence relation on a set S. Then the equivalence classes of R form a partition of S. Conversely, given a partition {A i | i I} of the set S, there is an equivalence relation R that has the sets A i, i I, as its equivalence classes.
19
Ex: if R={,,, } then S={,,,,, }
21
3 4 2 1 3 4 2 1
22
Warshall’s algorithm Let R is a relation in a set with n elements represented by matrix M R. Calculate the matrices W 0, W 1,..., W n where M R = W 0 W k is given by [w ij (k) ] where [w ij (k) ] = 1, if there exists a path from vertex i to j in the corresponding digraph, such that all the intermediate vertices of this path are in the set {1,2,…,k} 0, otherwise.
24
Partial order Relation A relation R on a set S is called a partial ordering or partial order if it is reflexive, antisymmetric, and transitive. A set S together with a partial ordering R is called a partially ordered set, or POSET and denoted by (S,R). A partial order R is also denoted as.
25
The elements a and b of a poset ( S, ) are called comparable if either a b or b a. Otherwise a and b are called incomparable. If (S, ) is a partial ordering set and every two elements of S are comparable, S is called a totally ordered or linearly ordered set. A totally ordered set is called a Chain.
26
Hasse Diagrams Given any partial order relation defined on a finite set, it is possible to draw the directed graph so that all of these properties are satisfied. This makes it possible to associate a somewhat simpler graph, called a Hasse diagram, with a partial order relation defined on a finite set.
27
Start with a directed graph of the relation in which all arrows point upward. Then eliminate: 1.the loops at all the vertices, 2.all arrows whose existence is implied by the transitive property, 3.the direction indicators on the arrows.
28
Let A = {1, 2, 3, 9, 19} and consider the “divides” relation on A : For all
29
For the poset ({1,2,3,4,6,8,12}, |)
30
S={2,3,5}, Hasse diagrams of (P(S), ⊆ ) and D 30 : D n indicates the poset with set of all intergers that divide n and the relation divides.
31
Extremal Elements: Maximal An element a in a poset (S, ≤) is called maximal if no element b in S exists such that, a ≤ b If there is one unique maximal element a, it is called the maximum element (or the greatest element)
32
Extremal Elements: Minimal An element a in a poset (S, ≤) is called minimal if no element b in S exists such that, b≤ a If there is one unique minimal element a, it is called the minimum element (or the least element)
34
Let (S, ≤) be a poset and let A S. If u is an element of S such that a ≤ u for all a A then u is an upper bound of A An element x that is an upper bound on a subset A and is less than all other upper bounds on A is called the least upper bound on A. We abbreviate it as lub.
35
Definition: Let (S, ≤) be a poset and let A S. If l is an element of S such that l ≤ a for all a A then l is an lower bound of A An element x that is a lower bound on a subset A and is greater than all other lower bounds on A is called the greatest lower bound on A. We abbreviate it glb.
36
Give lower/upper bounds & glb/lub of the sets: {d,e,f}, {a,c} and {b,d}
37
{d,e,f} Lower bounds: , thus no glb Upper bounds: , thus no lub {a,c} Lower bounds: , thus no glb Upper bounds: {h}, lub: h {b,d} Lower bounds: {b}, glb: b Upper bounds: {d,g}, lub: d because d ≤ g
38
Find all upper and lower bounds of the following subset of A: B 1 ={a, b}; B 2 ={c, d, e};
39
Find the LUB and GLB of B={6,7,10} for the following Hasse diagram. 1 2 3 4 5 6 7 8 10 9 11
40
Lattices A lattice is a partially ordered set in which every pair of elements has both – a least upper bound and – a greatest lower bound
42
Union, Intersection, Difference and Composition of Relations R: A B and S: A B R: A B and S: B C
43
Example: Let D and S be relations on A = {1, 2, 3, 4}. D = {(a, b) | b = 5 – a} S = {(a, b) | a < b} D = {(1, 4), (2, 3), (3, 2), (4, 1)} S = {(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)} D S = { (2, 4), (3, 3), (3, 4), (4, 2), (4, 3), (4, 4)}
44
Example: Let the relations R and S be represented by the matrices
45
Let A = [a ij ] be an m k zero-one matrix and B = [b ij ] be a k n zero-one matrix. Then the Boolean product of A and B, denoted by A B, is the m n matrix with (i, j)th entry [c ij ], where c ij = (a i1 b 1j ) (a i2 b 2i ) … (a ik b kj ). c ij = 1 if and only if at least one of the terms (a in b nj ) = 1 for some n; otherwise c ij = 0.
46
Let M A = [a ij ], M B = [b ij ] and M C = [c ij ] represent relations A, B, and C, respectively, and C = A B Then M C = M A M B M A B = M A M B
47
Functions For nonempty sets, A,B, a function, or mapping, f from A to B, denoted f:A→B, is a relation from A to B in which every element of A appears exactly once as the first component of an ordered pair in the relation. i.e domain(f)=A |f|=|A| Codomain=B
49
Properties of functions f: A B, is one-to-one or injective, if each element of B appears at most once as the image of an element of A. Therefore A B . f: A B, is one-to-one if and only if for all a 1, a 2 A, f(a 1 )=f(a 2 ) a 1 =a 2.
50
f: A B, is onto, or surjective, if range of f=B i.e., for all b B there is at least one a A with f(a)=B. Therefore A B .
51
f: A B, is one-to-one onto, or bijective, if f is both one-to-one and onto. Therefore A = B .
54
A function f is called invertible if the converse of f is also a function. The converse is called inverse function represented by f - 1.
55
The function is invertible if and only if it is one-to-one and onto, or bijective.
56
Discrete numeric functions (numeric functions) The class of functions whose domain is the set of natural numbers whose range is the set of real numbers
58
Operations of numeric functions
61
Shifting let a be a numeric function and i a positive integer function a is shifted i positions to the right
62
Find a 5
64
Find a -7
69
Recurrence Relation A recurrence relation is an infinite sequence a 1, a 2, a 3,…, a n,… in which the formula for the nth term a n depends on one or more preceding terms, with a finite set of start-up values or initial conditions
70
Examples Fibonacci sequence Initial conditions: f 1 = 1, f 2 = 1 Recursive formula: f n+1 = f n-1 + f n for n > 3 First few terms:
71
Compound interest Given –P = initial amount (principal) –n = number of years –r = annual interest rate –A = amount of money at the end of n years At the end of: 1 year: A = P + rP = P(1+r) 2 years: A = P + rP(1+r) = P(1+r) 2 3 years: A = P + rP(1+r) 2 = P(1+r) 3 … Obtain the formula A = P (1 + r) n
72
Examples Linear homogeneous a n = 1.2 a n-1 : degree 1 f n = f n-1 + f n-2 : degree 2 a n = 3a n-3 : degree 3 Non-linear homogeneous a n = a 2 n-1 + a n-2 a n = na n-1 - 2a n-2 Linear non-homogeneous a n = a n-1 + 2 n h n = 2h n-1 + 1 a n = 3a n-1 + n Non-linear non-homogeneous a n = a 2 n-1 + 2 n a n = n 2 a n-1 + n
73
73 The pigeonhole principle Suppose a flock of pigeons fly into a set of pigeonholes to roost If there are more pigeons than pigeonholes, then there must be at least 1 pigeonhole that has more than one pigeon in it If k+1 or more objects are placed into k boxes, then there is at least one box containing two or more of the objects
74
74 Pigeonhole principle examples In a group of 367 people, there must be two people with the same birthday – As there are 366 possible birthdays In a group of 27 English words, at least two words must start with the same letter – As there are only 26 letters
75
75 Generalized pigeonhole principle If N objects are placed into k boxes, then there is at least one box containing N/k objects
76
76 Generalized pigeonhole principle examples Among 100 people, there are at least 100/12 = 9 born on the same month How many students in a class must there be to ensure that 6 students get the same grade (one of A, B, C, D, or F)?
77
– The “boxes” are the grades. Thus, k = 5 – Thus, we set N/5 = 6 – Lowest possible value for N is 26
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.