Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

77
Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

Transcript of Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

Page 1: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

Unit II Discrete Structures

Relations and Functions

SE (Comp.Engg.)

Page 2: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

Cartesian productsThe Cartesian product of set A and set B is denoted by AB and equals {(a, b)aA and bB}. The elements of AB are ordered pairs. The elements of A1A2…An are ordered n-tuples.AB=AB

Page 3: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• Ex . A={2, 3, 4}, B={4, 5} , C={x,y}• A B ={<2,4>,<2,5>,<3,4>,<3,5>,<4,4>,<4,5>}

Page 4: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

Tree diagrams for the Cartesian product

Page 5: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

Relations

• Any subsets of AB is called a binary relation from A to B. Any subset of AA 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.

Page 6: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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

Page 7: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• 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.

Page 8: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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

Page 9: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

100

110

321

21

RM

Page 10: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

Graph Representation of a Relation

Page 11: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

Properties of Relations

• A relation R on a set A is called reflexive if (a, a)R for every element aA.

• A relation on a set A is called irreflexive if (a, a)R for every element aA.

Page 12: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

•A relation R on a set A is called symmetric if (b, a)R whenever (a, b)R for all a, bA.

•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,bA.

Page 13: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• 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, cA.

Page 14: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• 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.

Page 15: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

Equivalence Relations

• Any binary relation that is:ReflexiveSymmetricTransitive

Page 16: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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.

Page 17: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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, iI, forms a partition of S if and only if (i) Ai for iI

• Ai Aj = , if i j

• iI Ai = S

Page 18: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• 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 | iI} of the set S, there is an equivalence relation R that has the sets Ai, iI, as its equivalence classes.

Page 19: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

Ex: if R={<1,2>,<1,1>,<2,3>,<3,2><3,4>}then

S={<1,2>,<1,1>,<2,3>,<3,2><3,4>,<2,1>,<4,3>}

Page 20: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Page 21: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

3

42

1

3

42

1

Page 22: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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.

Page 23: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Page 24: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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 .

Page 25: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• 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.

Page 26: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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.

Page 27: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• 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.

Page 28: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• Let A = {1, 2, 3, 9, 19} and consider the “divides” relation on A:

• For all , , | for some integer .a b A a b b ka k

Page 29: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• For the poset ({1,2,3,4,6,8,12}, |)

Page 30: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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.

Page 31: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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)

Page 32: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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)

Page 33: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Page 34: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• Let (S, ≤) be a poset and let AS. If u is an element of S such that a ≤ u for all aA 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.

Page 35: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• Definition: Let (S, ≤) be a poset and let AS. If l is an element of S such that l ≤ a for all aA 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.

Page 36: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

Give lower/upper bounds & glb/lub of the sets:

{d,e,f}, {a,c} and {b,d}

Page 37: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

{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

Page 38: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• Find all upper and lower bounds of the following subset of A: B1={a, b}; B2={c, d, e};

Page 39: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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

Page 40: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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

Page 41: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Page 42: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

Union, Intersection, Difference and Composition of Relations

• R: AB and S: AB

• R: AB and S: BC

}),(),(|),{( SyxRyxBAyxSR

}),(),(|),{( SyxRyxBAyxSR

}),(),(|),{( SyxRyxBAyxSR

}),(),(|),{( RyxSyxBAyxRS

}),(),(,|),{( ScbRbaBbCAcaSR

Page 43: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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)}DS = { (2, 4), (3, 3), (3, 4), (4, 2), (4, 3), (4, 4)}

Page 44: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• Example: Let the relations R and S be represented by the matrices

011

111

101

SRSR MMM

001

110

101

SM

000

000

101

SRSR MMM

010

001

101

RM

Page 45: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• Let A = [aij] be an mk zero-one matrix and B = [bij] be a kn zero-one matrix.

• Then the Boolean product of A and B, denoted by AB, is the mn 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.

Page 46: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• Let MA = [aij], MB = [bij] and MC = [cij] represent relations A, B, and C, respectively, and C = AB

• Then MC = MAMB

• MAB = MAMB

Page 47: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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

Page 48: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Page 49: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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 AB.

f: AB, is one-to-one if and only if for all a1, a2A, f(a1)=f(a2) a1=a2.

Page 50: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• f: AB, is onto, or surjective, if range of f=Bi.e. , for all bB there is at least one aA with f(a)=B.

Therefore AB.

Page 51: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• f: AB, is one-to-one onto, or bijective, if f is both one-to-one and onto.

Therefore A=B.

Page 52: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

.each for

)),((=))((

bygiven is ,:

by denoted function, composite

then the,: and : If

Aa

afgafg

CAfg

CBgBAf

Page 53: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

( )( ) ( ( )) ( ) , ( ) , ( ) ,g f g f g a x gf x gf y 1 1 2 3 gf(4) = z

Page 54: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• 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.

Page 55: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• The function is invertible if and only if it is one-to-one and onto, or bijective.

Page 56: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

• 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

Page 57: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Page 58: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

Operations of numeric functions

Page 59: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Page 60: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Page 61: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

Shifting

• let a be a numeric function and i a positive integer

function a is shifted i positions to the right

Page 62: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

Find a5

Page 63: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Page 64: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

Find a-7

Page 65: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Page 66: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Page 67: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Page 68: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Page 69: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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

Page 70: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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:

Page 71: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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

Page 72: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

ExamplesLinear homogeneous• an = 1.2 an-1 : degree 1

• fn = fn-1 + fn-2 : degree 2

• an = 3an-3 : degree 3

Non-linear homogeneous• an = a2

n-1 + an-2

• an = nan-1 - 2an-2

Linear non-homogeneous• an = an-1 + 2n

• hn = 2hn-1 + 1

• an = 3an-1 + n

Non-linear non-homogeneous• an = a2

n-1 + 2n

• an = n2 an-1 + n

Page 73: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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

Page 74: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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

Page 75: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

75

Generalized pigeonhole principle

• If N objects are placed into k boxes, then there is at least one box containing N/k objects

Page 76: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

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

Page 77: Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)

– The “boxes” are the grades. Thus, k = 5– Thus, we set N/5 = 6– Lowest possible value for N is 26