Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 4.2: Relations Basics CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag.

Similar presentations


Presentation on theme: "Lecture 4.2: Relations Basics CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag."— Presentation transcript:

1 Lecture 4.2: Relations Basics CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag

2 10/27/2011Lecture 4.2 -- Relations Course Admin Mid-Term 2 Exam Solution will be posted soon Should have the results by the coming weekend HW3 Solution will be posted soon Results should be ready by the coming weekend

3 10/27/2011Lecture 4.2 -- Relations Outline Relation Examples and Definitions Matrix Representation Closures

4 10/27/2011 Composing Relations Q: Suppose R defined on N by: xRy iff y = x 2 and S defined on N by: xSy iff y = x 3 What is the composition S  R ? Lecture 4.2 -- Relations

5 10/27/2011 Composing Relations xRy iff y = x 2 xSy iff y = x 3 A: These are functions (squaring and cubing) so the composite S  R is just the function composition (raising to the 6 th power). xSRy iff y = x 6 (in this odd case S  R = R  S) Q: Compose the following: 1111 2222 3333 4445 Lecture 4.2 -- Relations

6 10/27/2011 Composing Relations 111 222 3334 5 A: Draw all possible shortcuts. In our case, all shortcuts went through 1:123 4 Lecture 4.2 -- Relations

7 10/27/2011 Composing Relations: Picture 111 222 3334 5 A: Draw all possible shortcuts. In our case, all shortcuts went through 1:123 4 Lecture 4.2 -- Relations

8 10/27/2011 Composing Relations: Picture 111 222 3334 5 A: Draw all possible shortcuts. In our case, all shortcuts went through 1:123 4 Lecture 4.2 -- Relations

9 10/27/2011 Composing Relations: Picture 111 222 3334 5 A: Draw all possible shortcuts. In our case, all shortcuts went through 1:123 4 Lecture 4.2 -- Relations

10 10/27/2011 Composing Relations: Picture 111 222 3334 5 A: Draw all possible shortcuts. In our case, all shortcuts went through 1:123 4 Lecture 4.2 -- Relations

11 10/27/2011 Inverting Relations Relational inversion amounts to just reversing all the tuples of a binary relation. DEF: If R is a relation from A to B, then the relation R -1 from B to A defined by setting bR -1 a if and only aRb. Q: Suppose R defined from Z to N by: xRy iff y = x 2. What is the inverse R -1 ? Lecture 4.2 -- Relations

12 10/27/2011 Inverting Relations A: xRy iff y = x 2. R is the square function so R -1 is square root: i.e. the union of the two square-root branches. I.e: yR -1 x iff y = x 2 or in terms of square root: xR -1 y iff y = ±  x where x is non-negative Lecture 4.2 -- Relations

13 Relations – matrix representation Suppose we have a relation R on AxB, where A={1,2,3,4}, and B={u,v,w}, R={(1,u),(1,v),(2,w),(3,w),(4,u)}. Then we can represent R as: The labels on the outside are for clarity. It’s really the matrix in the middle that’s important. This is a |A| x |B| matrix whose entries indicate membership in R. uvw 1110 2001 3001 4100 10/27/2011

14 Lecture 4.2 -- Relations Relations – matrix representation Some things to think about. Let R be a relation on a set A, and let M R be the matrix representation of R. Then R is reflexive if, ______________. A.All entries in M R are 1. B.The \ diagonal of M R contains only 1s. C.The first column of M R contains no 0s. D.None of the above. 10/27/2011

15 Lecture 4.2 -- Relations Relations – matrix representation Some things to think about. Let R be a relation on a set A, and let M R be the matrix representation of R. Then R is symmetric if, ______________. A.All entries above the \ are 1. B.The first and last columns of M R contain an equal # of 0s. C.M R is visually symmetric about the \ diagonal. D.None of the above. 10/27/2011

16 Lecture 4.2 -- Relations Relations – matrix representation Suppose we have R 1 and R 2 defined on A: R1R1 uvw u101 v001 w110 R2R2 uvw u110 v011 w001 Then R 1  R 2 is the bitwise “or” of the entries (Join By): Then R 1  R 2 is the bitwise “and” of the entries (Meet): 111 011 111 100 001 000 M R1  R2 = M R1 v M R2 M R1  R2 = M R1  M R2 10/27/2011

17 Lecture 4.2 -- Relations Relations – composition using matrices Suppose we have R and S defined on A: Ruvw u101 v001 w110 Suvw u110 v011 w001 Then S  R corresponds to the boolean product 111 001 111 10/27/2011

18 Cs173 - Spring 2004 Relations - A Theorem Theorem: If R is a transitive relation, then R n  R,  n. How to prove? What strategy or technique should we use?

19 Cs173 - Spring 2004 Relations - A Theorem If R is a transitive relation, then R n  R,  n. Typical way of proving subset. Proof by induction on n. Base case (n=1): R 1  R because by definition, R 1 = R. Induction case: if R is transitive, then R k  R. Prove: if R is transitive, then R k+1  R. We are trying to prove that R k+1  R. To do this, we select an element of R k+1 and show that it is also an element of R. Let (a,b) be an element of R k+1. Since R k+1 = R k  R, we know there is an x so that (a,x)  R and (x,b)  R k. By assumption at the induction step, since R k  R, (x,b)  R. But wait, if (a,x)  R, and (x,b)  R, and R is transitive, then (a,b)  R.

20 Cs173 - Spring 2004 Relations - Another Theorem If R is a reflexive relation, then R n is reflexive relation,  n. Whiteboard!

21 N-ary Relations So far, we were talking about binary relations – defined on two sets. Can be generalized to N sets Ex: R = {(a, b, c): a < b < c}, defined on set of integers – a 3-ary relation Applications in databases 10/27/2011Lecture 4.2 -- Relations

22 Closure Consider relation R={(1,2),(2,2),(3,3)} on the set A = {1,2,3,4}. Is R reflexive? What can we add to R to make it reflexive? No(1,1), (4,4) R’ = R U {(1,1),(4,4)} is called the reflexive closure of R. 10/27/2011

23 Lecture 4.2 -- Relations Today’s Reading Rosen 9.1 and 9.3


Download ppt "Lecture 4.2: Relations Basics CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag."

Similar presentations


Ads by Google