Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 4.1: Relations Basics

Similar presentations


Presentation on theme: "Lecture 4.1: Relations Basics"— Presentation transcript:

1 Lecture 4.1: Relations Basics
CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren

2 Course Admin Graded HW2 HW3 Due Will distribute today
Covers “Induction and Recursion” (Chapter 5) Due 11am Nov 6 (Thursday) 7/2/2018

3 Course Admin Mid Term 2 Nov 6 (Thur)
Covers “Induction and Recursion” (Chapter 5) Review Oct 30 (Thu) Study topics posted Sample practice exam will be given out soon 7/2/2018

4 Traveling Next Week At a conference (Nov 3-7):
Mid-term proctored by TA No class next Tuesday (Nov 4) – prepare for exam Office hrs extended – 3-5pm Thursday. 7/2/2018

5 Outline Relation Definition and Examples Types of Relations
Operations on Relations 7/2/2018

6 A x B = {<x,y> : xA and yB}.
Relations Recall the definition of the Cartesian (Cross) Product: The Cartesian Product of sets A and B, A x B, is the set A x B = {<x,y> : xA and yB}. A relation is just any subset of the CP!! R  AxB Ex: A = students; B = courses. R = {(a,b) | student a is enrolled in class b} We often say: aRb if (a,b) belongs to R 7/2/2018

7 Relations vs. Functions
Recall the definition of a function: f = {<a,b> : b = f(a) , aA and bB} Is every function a relation? Draw venn diagram of cross products, relations, functions Yes, a function is a special kind of relation. 7/2/2018

8 Properties of Relations
Reflexivity: A relation R on AxA is reflexive if for all aA, (a,a) R. Symmetry: A relation R on AxA is symmetric if (a,b)  R implies (b,a)  R . 7/2/2018

9 Properties of Relations
7/2/2018

10 Properties of Relations - Techniques
How can we check for the reflexive property? Draw a picture of the relation (called a “graph”). Vertex for every element of A Edge for every element of R Now, what’s R? {(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)} 1 2 3 4 Loops must exist on EVERY vertex. 7/2/2018

11 Properties of Relations - Techniques
How can we check for the symmetric property? Draw a picture of the relation (called a “graph”). Vertex for every element of A Edge for every element of R Now, what’s R? {(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)} EVERY edge must have a return edge. 1 2 3 4 7/2/2018

12 Properties of Relations - Techniques
How can we check for transitivity? Draw a picture of the relation (called a “graph”). Vertex for every element of A Edge for every element of R Now, what’s R? {(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)} 1 2 3 4 A “short cut” must be present for EVERY path of length 2. 7/2/2018

13 Properties of Relations - Techniques
How can we check for the anti-symmetric property? Draw a picture of the relation (called a “graph”). Vertex for every element of A Edge for every element of R Now, what’s R? {(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)} No edge can have a return edge. 1 2 3 4

14 Properties of Relations - Examples
Let R be a relation on People, R={(x,y): x and y have lived in the same country} 1 ? 1 2 ? 1 2 3 ? Is R transitive? No Is it symmetric? Yes Is it reflexive? Yes Is it anti-symmetric? No 7/2/2018

15 Properties of Relations - Examples
Let R be a relation on positive integers, R={(x,y): 3|(x-y)} Suppose (x,y) and (y,z) are in R. Definition of “divides” Then we can write 3j = (x-y) and 3k = (y-z) Can we say 3m = (x-z)? Is (x,z) in R? Add prev eqn to get: 3j + 3k = (x-y) + (y-z) 3(j + k) = (x-z) Is R transitive? Yes 7/2/2018

16 Properties of Relations - Techniques
Let R be a relation on positive integers, R={(x,y): 3|(x-y)} Is (x,x) in R, for all x? Definition of “divides” Does 3k = (x-x) for some k? Yes, for k=0. Is R transitive? Yes Is it reflexive? Yes 7/2/2018

17 Properties of Relations - Techniques
Let R be a relation on positive integers, R={(x,y): 3|(x-y)} Suppose (x,y) is in R. Definition of “divides” Then 3j = (x-y) for some j. Does 3k = (y-x) for some k? Yes, for k=-j. Is R transitive? Yes Is it symmetric? Yes Is it reflexive? Yes 7/2/2018

18 Properties of Relations - Techniques
Let R be a relation on positive integers, R={(x,y): 3|(x-y)} Suppose (x,y) is in R. Definition of “divides” Then 3j = (x-y) for some j. Does 3k = (y-x) for some k? Yes, for k=-j. Is R transitive? Yes Is it symmetric? Yes Is it reflexive? Yes Is it anti-symmetric? No 7/2/2018

19 More than one relation Suppose we have 2 relations, R1 and R2, and recall that relations are just sets! So we can take unions, intersections, complements, symmetric differences, etc. There are other things we can do as well… 7/2/2018

20 More than one relation SR = {(a,c):  bB, (a,b)  R, (b,c)  S}
Let R be a relation from A to B (R  AxB), and let S be a relation from B to C (S  BxC). The composition of R and S is the relation from A to C (SR  AxC): SR = {(a,c):  bB, (a,b)  R, (b,c)  S} A B C 1 2 3 4 x y z s t u v R S SR = {(1,u),(1,v),(2,t),(3,t),(4,u)} 7/2/2018

21 R2 = R1R = {(1,1),(1,2),(1,3),(2,3),(3,3),(4,1), (4,2)}
More than one relation Let R be a relation on A. Inductively define R1 = R Rn+1 = Rn  R A A A R R1 1 1 1 2 2 2 3 3 3 4 4 4 R2 = R1R = {(1,1),(1,2),(1,3),(2,3),(3,3),(4,1), (4,2)} 7/2/2018

22 R3 = R2R = {(1,1),(1,2),(1,3),(2,3),(3,3),(4,1),(4,2),(4,3)}
More than one relation Let R be a relation on A. Inductively define R1 = R Rn+1 = Rn  R A A A R R2 1 1 1 2 2 2 3 3 3 … = R4 = R5 = R6… 4 4 4 R3 = R2R = {(1,1),(1,2),(1,3),(2,3),(3,3),(4,1),(4,2),(4,3)} 7/2/2018

23 Today’s Reading Rosen 9.1 7/2/2018


Download ppt "Lecture 4.1: Relations Basics"

Similar presentations


Ads by Google