27
DISCRETE STRUCTURES WEEK2 LECTURE2

DISCRETE STRUCTURES - kau

  • Upload
    others

  • View
    15

  • Download
    0

Embed Size (px)

Citation preview

Page 1: DISCRETE STRUCTURES - kau

DISCRETE STRUCTURES

WEEK2

LECTURE2

Page 2: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 2

Representing RelationsRepresenting Relations••We already know different ways of representing relations. We already know different ways of representing relations. We will now take a closer look at two ways of We will now take a closer look at two ways of representation: representation: ZeroZero--one matricesone matrices and and directed graphsdirected graphs..

••If R is a relation from A = {aIf R is a relation from A = {a11, a, a22, …, a, …, amm} to B = } to B = {b{b11, b, b22, …, b, …, bnn}, then R can be represented by the zero}, then R can be represented by the zero--one one matrix Mmatrix MRR = [m= [mijij] with] with••mmijij = 1, if (a= 1, if (aii, b, bjj))R, andR, and••mmijij = 0, if (a= 0, if (aii, b, bjj))R.R.

••Note that for creating this matrix we first need to list the Note that for creating this matrix we first need to list the elements in A and B in a elements in A and B in a particular, but arbitrary orderparticular, but arbitrary order..

Page 3: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 3

Representing RelationsRepresenting Relations

••Example:Example: How can we represent the relation How can we represent the relation R = {(2, 1), (3, 1), (3, 2)} as a zeroR = {(2, 1), (3, 1), (3, 2)} as a zero--one matrix?one matrix?

••Solution:Solution: The matrix MThe matrix MRR is given by is given by

110100

RM

Page 4: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 4

Representing RelationsRepresenting Relations••What do we know about the matrices representing a What do we know about the matrices representing a relation on a setrelation on a set (a relation from A to A) ?(a relation from A to A) ?••They are They are square square matrices.matrices.••What do we know about matrices representing What do we know about matrices representing reflexivereflexiverelations?relations?••All the elements on the All the elements on the diagonaldiagonal of such matrices Mof such matrices Mrefrefmust be must be 1s1s..

1.

..

11

refM

Page 5: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 5

Representing RelationsRepresenting Relations••What do we know about the matrices representing What do we know about the matrices representing symmetric relationssymmetric relations??

••These matrices are symmetric, that is, MThese matrices are symmetric, that is, MRR = (M= (MRR))tt..

1101100100101101

RM

symmetric matrix,symmetric matrix,symmetric relation.symmetric relation.

0011001100110011

RM

nonnon--symmetric matrix,symmetric matrix,nonnon--symmetric relation.symmetric relation.

Page 6: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 6

Representing RelationsRepresenting Relations

••The Boolean operations The Boolean operations joinjoin and and meetmeet (you remember?) (you remember?) can be used to determine the matrices representing the can be used to determine the matrices representing the unionunion and the and the intersectionintersection of two relations, respectively.of two relations, respectively.

••To obtain the To obtain the joinjoin of two zeroof two zero--one matrices, we apply the one matrices, we apply the Boolean “or” function to all corresponding elements in the Boolean “or” function to all corresponding elements in the matrices.matrices.

••To obtain the To obtain the meetmeet of two zeroof two zero--one matrices, we apply the one matrices, we apply the Boolean “and” function to all corresponding elements in the Boolean “and” function to all corresponding elements in the matrices.matrices.

Page 7: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 7

Representing RelationsRepresenting Relations••Example:Example: Let the relations R and S be represented by the Let the relations R and S be represented by the matricesmatrices

011111101

SRSR MMM

001110101

SM

What are the matrices representing RWhat are the matrices representing R��S and RS and R��S?S?

Solution:Solution: These matrices are given byThese matrices are given by

000000101

SRSR MMM

010001101

RM

Page 8: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 8

Representing Relations Using MatricesRepresenting Relations Using Matrices

••Example:Example: How can we represent the relation How can we represent the relation R = {(2, 1), (3, 1), (3, 2)} as a zeroR = {(2, 1), (3, 1), (3, 2)} as a zero--one matrix?one matrix?

••Solution:Solution: The matrix MThe matrix MRR is given by is given by

110100

RM

Page 9: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 9

Representing Relations Using MatricesRepresenting Relations Using Matrices••Example:Example: Let the relations R and S be represented by the Let the relations R and S be represented by the matricesmatrices

011111101

SRSR MMM

001110101

SM

What are the matrices representing RWhat are the matrices representing R��S and RS and R��S?S?

Solution:Solution: These matrices are given byThese matrices are given by

000000101

SRSR MMM

010001101

RM

Page 10: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 10

Representing Relations Using MatricesRepresenting Relations Using MatricesDo you remember the Do you remember the Boolean product Boolean product of two zeroof two zero--one matrices?one matrices?

Let A = [aLet A = [aijij] be an m] be an m��k zerok zero--one matrix and one matrix and B = [bB = [bijij] be a k] be a k��n zeron zero--one matrix.one matrix.

Then the Then the Boolean productBoolean product of A and B, denoted by Aof A and B, denoted by A��B, is the mB, is the m��n matrix with (i, j)th entry n matrix with (i, j)th entry [c[cijij], where], where

ccijij = (a= (ai1i1 �� bb1j1j) ) �� (a(ai2i2 �� bb2i2i) ) �� … … �� (a(aikik �� bbkjkj). ).

ccijij = 1 if and only if at least one of the terms= 1 if and only if at least one of the terms(a(ainin �� bbnjnj) = 1 for some n; otherwise c) = 1 for some n; otherwise cijij = 0.= 0.

Page 11: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 11

Representing Relations Using MatricesRepresenting Relations Using MatricesLet us now assume that the zeroLet us now assume that the zero--one matrices one matrices MMA A = [a= [aijij], M], MBB = [b= [bijij] and M] and MCC = [c= [cijij] represent relations A, B, and C, respectively.] represent relations A, B, and C, respectively.

Remember:Remember: For MFor MCC = M= MAA��MMBB we have:we have:

ccijij = 1 if and only if at least one of the terms= 1 if and only if at least one of the terms(a(ainin �� bbnjnj) = 1 for some n; otherwise c) = 1 for some n; otherwise cijij = 0.= 0.

In terms of the In terms of the relationsrelations, this means that C contains a pair (x, this means that C contains a pair (xii, z, zjj) if and only if there is an ) if and only if there is an element yelement ynn such that (xsuch that (xii, y, ynn) is in relation A and ) is in relation A and (y(ynn, z, zjj) is in relation B.) is in relation B.

Therefore, C = BTherefore, C = B��A (A (compositecomposite of A and B).of A and B).

Page 12: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 12

Representing Relations Using MatricesRepresenting Relations Using Matrices

This gives us the following rule:This gives us the following rule:

MMBB��AA = M= MAA��MMBB

In other words, the matrix representing the In other words, the matrix representing the compositecomposite of relations A and B is the of relations A and B is the Boolean Boolean productproduct of the matrices representing A and B.of the matrices representing A and B.

Analogously, we can find matrices representing the Analogously, we can find matrices representing the powers of relationspowers of relations::

MMRRnn = M= MRR[n][n] (n(n--th th Boolean powerBoolean power).).

Page 13: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 13

Representing Relations Using MatricesRepresenting Relations Using Matrices••Example:Example: Find the matrix representing RFind the matrix representing R22, where the , where the matrix representing R is given bymatrix representing R is given by

001110010

RM

Solution:Solution: The matrix for RThe matrix for R22 is given byis given by

010111110

]2[2 RR

MM

Page 14: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 14

Representing Relations Using DigraphsRepresenting Relations Using Digraphs

••Definition:Definition: A A directed graphdirected graph, or , or digraphdigraph, consists of a set , consists of a set V of V of verticesvertices (or (or nodesnodes) together with a set E of ordered ) together with a set E of ordered pairs of elements of V called pairs of elements of V called edgesedges (or (or arcsarcs).).

••The vertex a is called the The vertex a is called the initial vertexinitial vertex of the edge (a, b), of the edge (a, b), and the vertex b is called the and the vertex b is called the terminal vertexterminal vertex of this edge.of this edge.

••We can use arrows to display graphs.We can use arrows to display graphs.

Page 15: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 15

Representing Relations Using DigraphsRepresenting Relations Using Digraphs

••Example:Example: Display the digraph with V = {a, b, c, d}, Display the digraph with V = {a, b, c, d}, E = {(a, b), (a, d), (b, b), (b, d), (c, a), (c, b), (d, b)}.E = {(a, b), (a, d), (b, b), (b, d), (c, a), (c, b), (d, b)}.

aabb

ccdd

An edge of the form (b, b) is called aAn edge of the form (b, b) is called a loop.loop.

Page 16: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 16

Representing Relations Using DigraphsRepresenting Relations Using Digraphs

••Obviously, we can represent any relation R on a set A by Obviously, we can represent any relation R on a set A by the digraph with A as its vertices and all pairs (a, b)the digraph with A as its vertices and all pairs (a, b)R as R as its edges.its edges.

••Vice versa, any digraph with vertices V and edges E can be Vice versa, any digraph with vertices V and edges E can be represented by a relation on V containing all the pairs in E.represented by a relation on V containing all the pairs in E.

••This This oneone--toto--one correspondenceone correspondence between relations and between relations and digraphs means that any statement about relations also digraphs means that any statement about relations also applies to digraphs, and vice versa.applies to digraphs, and vice versa.

Page 17: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 17

Equivalence Relations Equivalence Relations

••Equivalence relationsEquivalence relations are used to relate objects that are are used to relate objects that are similar in some way.similar in some way.

••Definition:Definition: A relation on a set A is called an equivalence A relation on a set A is called an equivalence relation if it is reflexive, symmetric, and transitive.relation if it is reflexive, symmetric, and transitive.

••Two elements that are related by an equivalence relation Two elements that are related by an equivalence relation R are called R are called equivalentequivalent..

Page 18: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 18

Equivalence Relations Equivalence Relations

••Since R is Since R is symmetricsymmetric, a is equivalent to b whenever b is , a is equivalent to b whenever b is equivalent to a.equivalent to a.

••Since R is Since R is reflexivereflexive, every element is equivalent to itself., every element is equivalent to itself.

••Since R is Since R is transitivetransitive, if a and b are equivalent and b and c , if a and b are equivalent and b and c are equivalent, then a and c are equivalent.are equivalent, then a and c are equivalent.

••Obviously, these three properties are necessary for a Obviously, these three properties are necessary for a reasonable definition of equivalence.reasonable definition of equivalence.

Page 19: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 19

Equivalence Relations Equivalence Relations ••Example:Example: Suppose that R is the relation on the set of Suppose that R is the relation on the set of strings that consist of English letters such that aRb if and strings that consist of English letters such that aRb if and only if l(a) = l(b), where l(x) is the length of the string x. Is R only if l(a) = l(b), where l(x) is the length of the string x. Is R an equivalence relation?an equivalence relation?

••Solution:Solution:

•• R is reflexive, because l(a) = l(a) and therefore R is reflexive, because l(a) = l(a) and therefore aRa for any string a.aRa for any string a.

•• R is symmetric, because if l(a) = l(b) then l(b) = R is symmetric, because if l(a) = l(b) then l(b) = l(a), so if aRb then bRa.l(a), so if aRb then bRa.

•• R is transitive, because if l(a) = l(b) and l(b) = l(c), R is transitive, because if l(a) = l(b) and l(b) = l(c), then l(a) = l(c), so aRb and bRc implies aRc.then l(a) = l(c), so aRb and bRc implies aRc.

••R is an equivalence relation.R is an equivalence relation.

Page 20: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 20

Equivalence Classes Equivalence Classes ••Definition: Definition: Let R be an equivalence relation on a set A. Let R be an equivalence relation on a set A. The set of all elements that are related to an element a of The set of all elements that are related to an element a of A is called the A is called the equivalence classequivalence classof a. of a.

••The equivalence class of a with respect to R is denoted by The equivalence class of a with respect to R is denoted by [a][a]RR..

••When only one relation is under consideration, we will When only one relation is under consideration, we will delete the subscript R and write delete the subscript R and write [a][a] for this equivalence for this equivalence class.class.

••If bIf b[a][a]RR, b is called a , b is called a representativerepresentative of this equivalence of this equivalence class.class.

Page 21: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 21

Equivalence Classes Equivalence Classes

••Example: Example: In the previous example (strings of identical In the previous example (strings of identical length), what is the equivalence class of the word mouse, length), what is the equivalence class of the word mouse, denoted by [mouse] ?denoted by [mouse] ?

••Solution:Solution: [mouse] is the set of all English words containing [mouse] is the set of all English words containing five letters.five letters.

••For example, ‘horse’ would be a representative of this For example, ‘horse’ would be a representative of this equivalence class.equivalence class.

••

Page 22: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 22

Equivalence Classes Equivalence Classes ••Theorem: Theorem: Let R be an equivalence relation on a set A. The Let R be an equivalence relation on a set A. The following statements are equivalent:following statements are equivalent:

•• aRbaRb

•• [a] = [b][a] = [b]

•• [a] [a] [b] [b] ••Definition:Definition: A A partition partition of a set S is a collection of disjoint of a set S is a collection of disjoint nonempty subsets of S that have S as their union. In other nonempty subsets of S that have S as their union. In other words, the collection of subsets Awords, the collection of subsets Aii, , iiI, forms a partition of S if and only if I, forms a partition of S if and only if (i) A(i) Aii for ifor iII

•• AAii AAjj = = , if i , if i jj

•• iiII AAii = S= S

Page 23: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 23

Equivalence Classes Equivalence Classes ••Examples: Examples: Let S be the set {u, m, b, r, o, c, k, s}.Let S be the set {u, m, b, r, o, c, k, s}.Do the following collections of sets partition S ?Do the following collections of sets partition S ?

{{m, o, c, k}, {r, u, b, s}}{{m, o, c, k}, {r, u, b, s}} yes.yes.

{{c, o, m, b}, {u, s}, {r}}{{c, o, m, b}, {u, s}, {r}} no (k is missing).no (k is missing).

{{b, r, o, c, k}, {m, u, s, t}}{{b, r, o, c, k}, {m, u, s, t}} no (t is not in S).no (t is not in S).

{{u, m, b, r, o, c, k, s}}{{u, m, b, r, o, c, k, s}} yes.yes.

{{b, o, o, k}, {r, u, m}, {c, s}}{{b, o, o, k}, {r, u, m}, {c, s}} yes ({b,o,o,k} = {b,o,k}).yes ({b,o,o,k} = {b,o,k}).

{{u, m, b}, {r, o, c, k, s}, {{u, m, b}, {r, o, c, k, s}, ��}} no (no (�� not allowed).not allowed).

Page 24: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 24

Equivalence Classes Equivalence Classes

••Theorem: Theorem: Let R be an equivalence relation on a Let R be an equivalence relation on a set S. Then the set S. Then the equivalence classesequivalence classes of R form a of R form a partitionpartition of of S. Conversely, given a partition S. Conversely, given a partition {A{Aii | i| iI} of the set S, there is an equivalence relation R that I} of the set S, there is an equivalence relation R that has the sets Ahas the sets Aii, i, iI, as its equivalence classes.I, as its equivalence classes.

Page 25: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 25

Equivalence Classes Equivalence Classes ••Example: Example: Let us assume that Frank, Suzanne and George Let us assume that Frank, Suzanne and George live in Boston, Stephanie and Max live in Lübeck, and live in Boston, Stephanie and Max live in Lübeck, and Jennifer lives in Sydney. Jennifer lives in Sydney.

••Let R be the Let R be the equivalence relationequivalence relation {(a, b) | a and b live in {(a, b) | a and b live in the same city} on the set P = {Frank, Suzanne, George, the same city} on the set P = {Frank, Suzanne, George, Stephanie, Max, Jennifer}.Stephanie, Max, Jennifer}.

••Then R = {(Frank, Frank), (Frank, Suzanne),Then R = {(Frank, Frank), (Frank, Suzanne),(Frank, George), (Suzanne, Frank), (Suzanne, Suzanne), (Frank, George), (Suzanne, Frank), (Suzanne, Suzanne), (Suzanne, George), (George, Frank),(Suzanne, George), (George, Frank),(George, Suzanne), (George, George), (Stephanie,(George, Suzanne), (George, George), (Stephanie,Stephanie), (Stephanie, Max), (Max, Stephanie),Stephanie), (Stephanie, Max), (Max, Stephanie),(Max, Max), (Jennifer, Jennifer)}.(Max, Max), (Jennifer, Jennifer)}.

Page 26: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 26

Equivalence Classes Equivalence Classes

••Then the Then the equivalence classesequivalence classes of R are:of R are:

••{{Frank, Suzanne, George}, {Stephanie, Max}, {Jennifer}}.{{Frank, Suzanne, George}, {Stephanie, Max}, {Jennifer}}.

••This is a This is a partition partition of P.of P.

••The equivalence classes of any equivalence relation R The equivalence classes of any equivalence relation R defined on a set S constitute a partition of S, because every defined on a set S constitute a partition of S, because every element in S is assigned to element in S is assigned to exactly oneexactly one of the equivalence of the equivalence classes.classes.

Page 27: DISCRETE STRUCTURES - kau

3/12/2010 CPCS 222 - Discrete Structures 27

Equivalence Classes Equivalence Classes

••Another example: Another example: Let R be the relation Let R be the relation {(a, b) | a {(a, b) | a b (mod 3)} on the set of integers.b (mod 3)} on the set of integers.

••Is R an equivalence relation?Is R an equivalence relation?

••Yes, R is reflexive, symmetric, and transitive.Yes, R is reflexive, symmetric, and transitive.

••What are the equivalence classes of R ?What are the equivalence classes of R ?

••{{…, {{…, --6, 6, --3, 0, 3, 6, …},3, 0, 3, 6, …},{…, {…, --5, 5, --2, 1, 4, 7, …},2, 1, 4, 7, …},{…, {…, --4, 4, --1, 2, 5, 8, …}}1, 2, 5, 8, …}}