unit-2-relation-function.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

SE (Comp.Engg.) Unit II Discrete Structures Relations and Functions 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 A1A2…An are ordered n-tuples. AB=AB E...

SE (Comp.Engg.) Unit II Discrete Structures Relations and Functions 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 A1A2…An are ordered n-tuples. AB=AB Ex. A={2, 3, 4}, B={4, 5} , C={x,y} A  B ={,,,,,} Tree diagrams for the Cartesian product 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 2mn relations from A to B. Example: Let A = {1, 2, 3, 4}. Which ordered pairs are in the relation R = {(a, b) | a < b} ? (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)} 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} 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. Matrix Representation of a Relation MR = [mij] (where i=row, j=col) § mij={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)} Graph Representation of a Relation 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. 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. 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. 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. Equivalence Relations Any binary relation that is: Reflexive Symmetric Transitive 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. 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 Ai, iI, forms a partition of S if and only if (i) Ai   for iI Ai  Aj = , if i  j iI Ai = S 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 {Ai | iI} of the set S, there is an equivalence relation R that has the sets Ai, iI, as its equivalence classes. Ex: if R={,,,} then S={,,,,,} 3 3 1 1 4 4 2 2 Warshall’s algorithm Let R is a relation in a set with n elements represented by matrix MR. Calculate the matrices W0, W1,... , Wn where MR = W0 Wk is given by [wij(k)] where [wij(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. 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. 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. 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. 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. Let A = {1, 2, 3, 9, 19} and consider the “divides” relation on A: For all For the poset ({1,2,3,4,6,8,12}, |) S={2,3,5}, Hasse diagrams of (P(S), ⊆) and D30: Dn indicates the poset with set of all intergers that divide n and the relation divides. 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) 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) 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. 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. Give lower/upper bounds & glb/lub of the sets: {d,e,f}, {a,c} and {b,d} {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 Find all upper and lower bounds of the following subset of A: B1={a, b}; B2={c, d, e}; Find the LUB and GLB of B={6,7,10} for the following Hasse diagram. 11 10 9 8 5 6 7 3 4 2 1 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 Union, Intersection, Difference and Composition of Relations R: AB and S: AB R: AB and S: BC 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)} Example: Let the relations R and S be represented by the matrices Let A = [aij] be an mk zero-one matrix and B = [bij] 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 [cij], where cij = (ai1  b1j)  (ai2  b2i)  …  (aik  bkj). cij = 1 if and only if at least one of the terms (ain  bnj) = 1 for some n; otherwise cij = 0. Let MA = [aij], MB = [bij] and MC = [cij] represent relations A, B, and C, respectively, and C = AB Then MC = MAMB MAB = MAMB 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 Properties of functions f: AB, 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: AB, is one-to-one if and only if for all a1, a2A, f(a1)=f(a2) a1=a2. f: AB, 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. f: AB, is one-to-one onto, or bijective, if f is both one-to-one and onto. Therefore A=B. A function f is called invertible if the converse of f is also a function. The converse is called -1 inverse function represented by f. The function is invertible if and only if it is one-to-one and onto, or bijective. 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 Operations of numeric functions Shifting let a be a numeric function and i a positive integer function a is shifted i positions to the right Find a5 Find a-7 Recurrence Relation A recurrence relation Ø is an infinite sequence a1, a2, a3,…, an,… Ø in which the formula for the nth term an depends on one or more preceding terms, Ø with a finite set of start-up values or initial conditions Examples Fibonacci sequence Initial conditions: f1 = 1, f2 = 1 Recursive formula: f n+1 = f n-1 + f n for n > 3 First few terms: 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: q 1 year: A = P + rP = P(1+r) q 2 years: A = P + rP(1+r) = P(1+r)2 q 3 years: A = P + rP(1+r)2 = P(1+r)3 … Obtain the formula A = P (1 + r) n Examples Linear homogeneous Linear non-homogeneous an = 1.2 an-1 : degree 1 an = an-1 + 2n fn = fn-1 + fn-2 : degree 2 hn = 2hn-1 + 1 an = 3an-3 : degree 3 an = 3an-1 + n Non-linear homogeneous Non-linear non-homogeneous an = a2n-1 + an-2 an = a2n-1 + 2n an = nan-1 - 2an-2 an = n2 an-1 + n 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 73 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 74 Generalized pigeonhole principle If N objects are placed into k boxes, then there is at least one box containing N/k objects 75 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)? 76 – The “boxes” are the grades. Thus, k = 5 – Thus, we set N/5 = 6 – Lowest possible value for N is 26

Use Quizgecko on...
Browser
Browser