Rela%ons and Their Proper%es. Slides by A. Bloomfield

Similar documents
Definition: A binary relation R from a set A to a set B is a subset R A B. Example:

Section Summary. Relations and Functions Properties of Relations. Combining Relations

Notes. Relations. Introduction. Notes. Relations. Notes. Definition. Example. Slides by Christopher M. Bourke Instructor: Berthe Y.

Relations Graphical View

Relations. Relations of Sets N-ary Relations Relational Databases Binary Relation Properties Equivalence Relations. Reading (Epp s textbook)

Chapter 9: Relations Relations

Definition: A binary relation R from a set A to a set B is a subset R A B. Example:

What are relations? f: A B

Relations. We have seen several types of abstract, mathematical objects, including propositions, predicates, sets, and ordered pairs and tuples.

CSC Discrete Math I, Spring Relations

Outline Inverse of a Relation Properties of Relations. Relations. Alice E. Fischer. April, 2018

Packet #5: Binary Relations. Applied Discrete Mathematics

Today. Binary relations establish a relationship between elements of two sets

COMP 182 Algorithmic Thinking. Relations. Luay Nakhleh Computer Science Rice University

Relations. Relations. Definition. Let A and B be sets.

MAD 3105 PRACTICE TEST 2 SOLUTIONS

Relationships between elements of sets occur in many contexts. Every day we deal with

Math.3336: Discrete Mathematics. Chapter 9 Relations

Equivalence relations

MITOCW Lec 11 MIT 6.042J Mathematics for Computer Science, Fall 2010

Week 4-5: Binary Relations

Discrete Mathematics. 2. Relations

n CS 160 or CS122 n Sets and Functions n Propositions and Predicates n Inference Rules n Proof Techniques n Program Verification n CS 161

Section 8.4 Closures of Relations

Week 4-5: Binary Relations

Math 42, Discrete Mathematics

Relations --- Binary Relations. Debdeep Mukhopadhyay IIT Madras

Equivalence, Order, and Inductive Proof

CS 161: Design and Analysis of Algorithms

CHAPTER 1. Relations. 1. Relations and Their Properties. Discussion

Reading 11 : Relations and Functions

5. Partitions and Relations Ch.22 of PJE.

Chapter 2 - Basics Structures

Selected Solutions to Even Problems, Part 3

EQUIVALENCE RELATIONS (NOTES FOR STUDENTS) 1. RELATIONS

Automata and Languages

Sets are one of the basic building blocks for the types of objects considered in discrete mathematics.

Multiple Choice Questions for Review

Massachusetts Institute of Technology 6.042J/18.062J, Fall 02: Mathematics for Computer Science Professor Albert Meyer and Dr.

Discrete Basic Structure: Sets

Notes for Science and Engineering Foundation Discrete Mathematics

Department of Computer Science University at Albany, State University of New York Solutions to Sample Discrete Mathematics Examination II (Fall 2007)

REVIEW QUESTIONS. Chapter 1: Foundations: Sets, Logic, and Algorithms

Chapter 2 - Basics Structures MATH 213. Chapter 2: Basic Structures. Dr. Eric Bancroft. Fall Dr. Eric Bancroft MATH 213 Fall / 60

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

0 Sets and Induction. Sets

W3203 Discrete Mathema1cs. Coun1ng. Spring 2015 Instructor: Ilia Vovsha.

Discrete Structures: Sample Questions, Exam 2, SOLUTIONS

1 Basic Combinatorics

Polynomials and Gröbner Bases

Combinatorics Sec/on of Rosen Ques/ons

W3203 Discrete Mathema1cs. Logic and Proofs. Spring 2015 Instructor: Ilia Vovsha. hcp://

Mathematics 220 Homework 4 - Solutions. Solution: We must prove the two statements: (1) if A = B, then A B = A B, and (2) if A B = A B, then A = B.

1. To be a grandfather. Objects of our consideration are people; a person a is associated with a person b if a is a grandfather of b.

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata

DRAFT CONCEPTUAL SOLUTION REPORT DRAFT

Mathematics Course 111: Algebra I Part I: Algebraic Structures, Sets and Permutations

MATH 215 Sets (S) Definition 1 A set is a collection of objects. The objects in a set X are called elements of X.

Sets and Motivation for Boolean algebra

Diagnostic quiz for M303: Further Pure Mathematics

Preparing for the CS 173 (A) Fall 2018 Midterm 1

1. SET 10/9/2013. Discrete Mathematics Fajrian Nur Adnan, M.CS

CS Discrete Mathematics Dr. D. Manivannan (Mani)

CSC 1700 Analysis of Algorithms: Warshall s and Floyd s algorithms

An Introduction to the Concept of Relations

1.A Sets, Relations, Graphs, and Functions 1.A.1 Set a collection of objects(element) Let A be a set and a be an elements in A, then we write a A.

Exercises for Discrete Maths

Computational Models - Lecture 4

Exam 2. Is g one-to-one? Is g onto? Why? Solution: g is not one-to-one, since for c A, g(b) = g(c) = c. g is not onto, since a / g(a).

Divisor Problems HAROLD B. REITER.

CHAPTER THREE: RELATIONS AND FUNCTIONS

MATH 61-02: PRACTICE PROBLEMS FOR FINAL EXAM

CMPSCI 250: Introduction to Computation. Lecture #11: Equivalence Relations David Mix Barrington 27 September 2013

Discrete Mathematics. Chapter 4. Relations and Digraphs Sanguk Noh

Just the Factors, Ma am HAROLD B. REITER.

At least one of us is a knave. What are A and B?

CS 514, Mathematics for Computer Science Mid-semester Exam, Autumn 2017 Department of Computer Science and Engineering IIT Guwahati

Sets, Functions and Relations

Chapter 6. Relations. 6.1 Relations

Normaliza)on and Func)onal Dependencies

Orders and Equivalences

Set theory. Math 304 Spring 2007

Name (please print) Mathematics Final Examination December 14, 2005 I. (4)

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Notation Index. gcd(a, b) (greatest common divisor) NT-16

Discrete Structures (2IT50)

Supplementary Material for MTH 299 Online Edition

MATH 363: Discrete Mathematics

Definitions: A binary relation R on a set X is (a) reflexive if x X : xrx; (f) asymmetric if x, x X : [x Rx xr c x ]

Basic Combinatorics. Math 40210, Section 01 Fall Homework 8 Solutions

Discrete Structures, Final Exam

Discrete Mathematics. W. Ethan Duckworth. Fall 2017, Loyola University Maryland

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers

ABOUT THE CLASS AND NOTES ON SET THEORY

Exam in Discrete Mathematics

Sets. We discuss an informal (naive) set theory as needed in Computer Science. It was introduced by G. Cantor in the second half of the nineteenth

Lecture Notes 1 Basic Concepts of Mathematics MATH 352

HL Topic. Sets, relations and groups. (Further Mathematics SL Topic 3) Sets Ordered pairs Functions Binary operations Groups Further groups

Harvard CS121 and CSCI E-121 Lecture 2: Mathematical Preliminaries

2 Equivalence Relations

Transcription:

Rela%ons and Their Proper%es Slides by A. Bloomfield

What is a rela%on Let A and B be sets. A binary rela%on R is a subset of A B Example Let A be the students in a the CS major A = {Alice, Bob, Claire, Dan} Let B be the courses the department offers B = {CS, CS2, CS22} We specify rela%on R = A B as the set that lists all students a A enrolled in class b B R = { (Alice, CS), (Bob, CS2), (Bob, CS22), (Dan, CS2), (Dan, CS22) } 2

More rela%on examples Another rela%on example: Let A be the ci%es in the US Let B be the states in the US We define R to mean a is a city in state b Thus, the following are in our rela%on: (C ville, VA) (Philadelphia, PA) (Portland, MA) (Portland, OR) etc Most rela%ons we will see deal with ordered pairs of integers 3

Represen%ng rela%ons We can represent relations graphically: We can represent relations in a table: Alice Bob Claire Dan CS CS2 CS22 Alice CS CS2 CS22 X Bob X X Claire Dan X X Not valid functions! 4

Rela%ons vs. func%ons Not all rela%ons are func%ons But consider the following func%on: a b c d 2 3 4 All func%ons are rela%ons! 5

When to use which? A func%on is used when you need to obtain a SINGLE result for any element in the domain Example: sin, cos, tan A rela%on is when there are mul%ple mappings between the domain and the co- domain Example: students enrolled in mul%ple courses 6

Rela%ons on a set A rela%on on the set A is a rela%on from A to A In other words, the domain and co- domain are the same set We will generally be studying rela%ons of this type 7

Rela%ons on a set Let A be the set {, 2, 3, 4 } Which ordered pairs are in the rela%on R = { (a,b) a divides b } R = { (,), (,2), (,3), (,4), (2,2), (2,4), (3,3), (4,4) } R 2 3 4 2 2 X X X X 2 X X 3 3 3 X 4 4 4 X 8

More examples Consider some rela%ons on the set Z Are the following ordered pairs in the rela%on? R = { (a,b) a b } R 2 = { (a,b) a>b } R 3 = { (a,b) a= b } R 4 = { (a,b) a=b } R 5 = { (a,b) a=b+ } R 6 = { (a,b) a+b 3 } (,) (,2) (2,) (,- ) (2,2) X X X X X X X X X X X X X X X 9

Rela%on proper%es Six proper%es of rela%ons we will study: Reflexive Irreflexive Symmetric Asymmetric An%symmetric Transi%ve

Reflexivity A rela%on is reflexive if every element is related to itself Or, (a,a) R Examples of reflexive rela%ons: =,, Examples of rela%ons that are not reflexive: <, >

Irreflexivity A rela%on is irreflexive if every element is not related to itself Or, (a,a) R Irreflexivity is the opposite of reflexivity Examples of irreflexive rela%ons: <, > Examples of rela%ons that are not irreflexive: =,, 2

Reflexivity vs. Irreflexivity A rela%on can be neither reflexive nor irreflexive Some elements are related to themselves, others are not We will see an example of this later on 3

Symmetry A rela%on is symmetric if, for every (a,b) R, then (b,a) R Examples of symmetric rela%ons: =, istwinof() Examples of rela%ons that are not symmetric: <, >,, 4

Asymmetry A rela%on is asymmetric if, for every (a,b) R, then (b,a) R Asymmetry is the opposite of symmetry Examples of asymmetric rela%ons: <, > Examples of rela%ons that are not asymmetric: =, istwinof(),, 5

An%symmetry A rela%on is an%symmetric if, for every (a,b) R, then (b,a) R is true only when a=b An%symmetry is not the opposite of symmetry Examples of an%symmetric rela%ons: =,, Examples of rela%ons that are not an%symmetric: <, >, istwinof() 6

Notes on *symmetric rela%ons A rela%on can be neither symmetric or asymmetric R = { (a,b) a= b } This is not symmetric - 4 is not related to itself This is not asymmetric 4 is related to itself Note that it is an%symmetric 7

Transi%vity A rela%on is transi%ve if, for every (a,b) R and (b,c) R, then (a,c) R If a < b and b < c, then a < c Thus, < is transi%ve If a = b and b = c, then a = c Thus, = is transi%ve 8

Transi%vity examples Consider isancestorof() Let Alice be Bob s parent, and Bob be Claire s parent Thus, Alice is an ancestor of Bob, and Bob is an ancestor of Claire Thus, Alice is an ancestor of Claire Thus, isancestorof() is a transi%ve rela%on Consider isparentof() Let Alice be Bob s parent, and Bob be Claire s parent Thus, Alice is a parent of Bob, and Bob is a parent of Claire However, Alice is not a parent of Claire Thus, isparentof() is not a transi%ve rela%on 9

Rela%ons of rela%ons summary = < > Reflexive X X X Irreflexive X X Symmetric X Asymmetric X X Antisymmetric X X X Transitive X X X X X 2

Combining rela%ons There are two ways to combine rela%ons R and R 2 Via Boolean operators Via rela%on composi%on 2

Combining rela%ons via Boolean operators Consider two rela%ons R and R We can combine them as follows: R U R = all numbers OR That s all the numbers R R = all numbers AND That s all numbers equal to R R = all numbers or, but not both That s all numbers not equal to R - R = all numbers that are not also That s all numbers strictly greater than R - R = all numbers that are not also That s all numbers strictly less than Note that it s possible the result is the empty set 22

Combining rela%ons via rela%onal composi%on Let R be a rela%on from A to B, and S be a rela%on from B to C Let a A, b B, and c C Let (a,b) R, and (b,c) S Then the composite of R and S consists of the ordered pairs (a,c) We denote the rela%on by S R Note that S comes first when wri%ng the composi%on! 23

Combining rela%ons via rela%onal composi%on Let M be the rela%on is mother of Let F be the rela%on is father of What is M F? If (a,b) F, then a is the father of b If (b,c) M, then b is the mother of c Thus, M F denotes the rela%on maternal grandfather What is F M? If (a,b) M, then a is the mother of b If (b,c) F, then b is the father of c Thus, F M denotes the rela%on paternal grandmother What is M M? If (a,b) M, then a is the mother of b If (b,c) M, then b is the mother of c Thus, M M denotes the rela%on maternal grandmother Note that M and F are not transi%ve rela%ons!!! 24

Combining rela%ons via rela%onal composi%on Given rela%on R R R can be denoted by R 2 R 2 R = (R R) R = R 3 Example: M 3 is your mother s mother s mother 25

Represen%ng Rela%ons Slides by A. Bloomfield 26

In this slide set Matrix review Two ways to represent rela%ons Via matrices Via directed graphs 27

28 Matrix review This is from Rosen, page 2 and 22 We will only be dealing with zero- one matrices Each element in the matrix is either a or a These matrices will be used for Boolean opera%ons is true, is false

29 Matrix transposi%on Given a matrix M, the transposi%on of M, denoted M t, is the matrix obtained by switching the columns and rows of M In a square matrix, the main diagonal stays unchanged = 6 5 4 3 2 M = 6 5 4 3 2 9 8 7 6 5 4 3 2 M = 6 3 5 2 4 t M = 6 2 8 4 5 7 3 4 6 2 3 9 5 t M

3 Matrix join A join of two matrices performs a Boolean OR on each rela%ve entry of the matrices Matrices must be the same size Denoted by the or symbol: =

3 Matrix meet A meet of two matrices performs a Boolean AND on each rela%ve entry of the matrices Matrices must be the same size Denoted by the or symbol: =

32 Matrix Boolean product A Boolean product of two matrices is similar to matrix mul%plica%on Instead of the sum of the products, it s the conjunc%on (and) of the disjunc%ons (ors) Denoted by the or symbol: 4,,4 3,,3 2,,2,,, * * * * b a b a b a b a c + + + = 4,,4 3,,3 2,,2,,, b a b a b a b a c = = = =

Rela%ons using matrices List the elements of sets A and B in a par%cular order Order doesn t maner, but we ll generally use ascending order Create a matrix M = m ] R [ ij m ij = if if ( a, b i ( a, b i j ) R j ) R 33

Rela%ons using matrices Consider the rela%on of who is enrolled in which class Let A = { Alice, Bob, Claire, Dan } Let B = { CS, CS2, CS22 } R = { (a,b) person a is enrolled in course b } CS CS2 CS22 Alice X Bob X X Claire Dan X X M R = 34

Rela%ons using matrices What is it good for? It is how computers view rela%ons A 2- dimensional array Very easy to view rela%onship proper%es We will generally consider rela%ons on a single set In other words, the domain and co- domain are the same set And the matrix is square 35

36 Reflexivity Consider a reflexive rela%on: One which every element is related to itself Let A = {, 2, 3, 4, 5 } = M If the center (main) diagonal is all s, a relation is reflexive

37 Irreflexivity Consider a reflexive rela%on: < One which every element is not related to itself Let A = {, 2, 3, 4, 5 } = M If the center (main) diagonal is all s, a relation is irreflexive

38 = M Symmetry Consider an symmetric rela%on R One which if a is related to b then b is related to a for all (a,b) Let A = {, 2, 3, 4, 5 } If, for every value, it is the equal to the value in its transposed position, then the relation is symmetric

Asymmetry Consider an asymmetric rela%on: < One which if a is related to b then b is not related to a for all (a,b) Let A = {, 2, 3, 4, 5 } M = If, for every value and t h e v a l u e i n i t s transposed position, if they are not both, then the relation is asymmetric An asymmetric relation must also be irreflexive Thus, the main diagonal must be all s 39

An%symmetry Consider an an%symmetric rela%on: One which if a is related to b then b is not related to a unless a=b for all (a,b) Let A = {, 2, 3, 4, 5 } If, for every value and the value in its M = transposed position, if they are not both, then the relation is antisymmetric The center diagonal can have both s and s 4

Transi%vity Consider an transi%ve rela%on: One which if a is related to b and b is related to c then a is related to c for all (a,b), (b,c) and (a,c) Let A = {, 2, 3, 4, 5 } M = If, for every spot (a,b) and (b,c) that each have a, there is a at (a,c), then the relation is transitive Matrices don t show this property easily 4

42 Combining rela%ons: via Boolean operators Example 4 from Rosen, sec%on 7.3 Let: Join: Meet: = M R = M S = = S R S R M M M = = S R S R M M M

43 Combining rela%ons: via rela%on composi%on Example 4 from Rosen, sec%on 7.3 Let: But why is this the case? = M R = M S = = S R R S M M M a b c d e f d e f g h i a b c g h i

Represen%ng rela%ons using directed A directed graph consists of: A set V of ver%ces (or nodes) A set E of edges (or arcs) graphs If (a, b) is in the rela%on, then there is an arrow from a to b Will generally use rela%ons on a single set Consider our rela%on R = { (a,b) a divides b } Old way: 2 2 2 3 3 3 4 4 4 44

Reflexivity Consider a reflexive rela%on: One which every element is related to itself Let A = {, 2, 3, 4, 5 } 2 If every node has a loop, a relation is reflexive 5 3 4 45

Irreflexivity Consider a reflexive rela%on: < One which every element is not related to itself Let A = {, 2, 3, 4, 5 } 2 If every node does not have a loop, a relation is irreflexive 5 3 4 46

Symmetry Consider an symmetric rela%on R One which if a is related to b then b is related to a for all (a,b) Let A = {, 2, 3, 4, 5 } If, for every edge, there 2 5 3 4 Called antiparallel pairs Note that this relation is neither reflexive nor irreflexive! is an edge in the other direction, then the relation is symmetric Loops are allowed, and do not need edges in the other direction 47

Asymmetry Consider an asymmetric rela%on: < One which if a is related to b then b is not related to a for all (a,b) Let A = {, 2, 3, 4, 5 } A digraph is asymmetric if: 2 5 3 4. If, for every edge, there is not an edge in the other direction, then the relation is asymmetric 2. Loops are not allowed in an asymmetric digraph (recall it must be 48 irreflexive)

An%symmetry Consider an an%symmetric rela%on: One which if a is related to b then b is not related to a unless a=b for all (a,b) Let A = {, 2, 3, 4, 5 } 2 If, for every edge, there is not an edge in the other direction, then the relation is antisymmetric 5 3 4 Loops are allowed in the digraph 49

Transi%vity Consider an transi%ve rela%on: One which if a is related to b and b is related to c then a is related to c for all (a,b), (b,c) and (a,c) Let A = {, 2, 3, 4, 5 } 2 5 3 A digraph is transitive if, for there is a edge from a to c when there is a edge from a to b and from b to c 4 5

Applica%ons of digraphs: MapQuest Not reflexive Is irreflexive Not symmetric Not asymmetric Not antisymmetric Not transitive End Not reflexive Is irreflexive Is symmetric Not asymmetric Not antisymmetric Not transitive Start 5

Rosen, ques%ons 3 & 32, sec%on 7.3 Which of the graphs are reflexive, irreflexive, symmetric, asymmetric, antisymmetric, or transitive 23 24 25 26 27 28 Reflexive Y Y Y Irreflexive Y Y Symmetric Asymmetric A n t i - symmetric Transitive Y Y Y Y Y Y 52

Rosen, sec%on 7. (sic) ques%on 45 (a) How many symmetric rela%ons are there on a set with n elements? Solu%on guide explana%on is preny poorly worded So instead we ll use matrices 53

Rosen, sec%on 7. (sic) ques%on 45 (a) Consider the matrix represen%ng symmetric rela%on R on a set with n elements: The center diagonal can have any values Once the upper triangle is determined, the lower triangle must be the transposed version of the upper one How many ways are there to fill in the center diagonal and the upper triangle? There are n 2 elements in the matrix There are n elements in the center diagonal Thus, there are 2 n ways to fill in s and s in the diagonal Thus, there are (n 2 - n)/2 elements in each triangle Thus, there are ( n 2 n)/2 ways to fill in s and s in the triangle 2 2 *2 2 = 2 n ( n n)/2 ( n + n)/2 Answer: there are possible symmetric rela%ons on a set with n elements 2 54

Closures of Rela%ons Slides by A. Bloomfield 55

Rela%onal closures Three types we will study Reflexive Easy Symmetric Easy Transi%ve Hard 56

Reflexive closure Consider a rela%on R: From our MapQuest example in the last slide set Note that it is not reflexive We want to add edges to make the rela%on reflexive By adding those edges, we have made a non- reflexive rela%on R into a reflexive rela%on This new rela%on is called the reflexive closure of R 57

Reflexive closure In order to find the reflexive closure of a rela%on R, we add a loop at each node that does not have one The reflexive closure of R is R U Δ Where Δ = { (a,a) a R } Called the diagonal rela%on With matrices, we set the diagonal to all s 58

Rosen, sec%on 7.4, ques%on (a) Let R be a rela%on on the set {,, 2, 3 } containing the ordered pairs (,), (,), (,2), (2,), (2,2), and (3,) What is the reflexive closure of R? We add all pairs of edges (a,a) that do not already exist We add edges: (,), (3,3) 3 2 59

Symmetric closure Consider a rela%on R: From our MapQuest example in the last slide set Note that it is not symmetric We want to add edges to make the rela%on symmetric By adding those edges, we have made a non- symmetric rela%on R into a symmetric rela%on This new rela%on is called the symmetric closure of R 6

Symmetric closure In order to find the symmetric closure of a rela%on R, we add an edge from a to b, where there is already an edge from b to a The symmetric closure of R is R U R - If R = { (a,b) } Then R - = { (b,a) } 6

Rosen, sec%on 7.4, ques%on (b) Let R be a rela%on on the set {,, 2, 3 } containing the ordered pairs (,), (,), (,2), (2,), (2,2), and (3,) What is the symmetric closure of R? We add all pairs of edges (a,b) where (b,a) exists We make all single edges into an%- parallel pairs 3 2 We add edges: (,2), (,3) (,), (2,) 62

Paths in directed graphs A path is a sequences of connected edges from vertex a to vertex b No path exists from the noted start loca%on A path that starts and ends at the same vertex is called a circuit or cycle Must have length Start (a) Start (a) End (b) End (b) Start (a) 63

More on paths The length of a path is the number of edges in the path, not the number of nodes 64

Transi%ve closure The transitive closure would contain edges between all nodes reachable by a path of any length 65

Transi%ve closure Informal defini%on: If there is a path from a to b, then there should be an edge from a to b in the transi%ve closure First take of a defini%on: In order to find the transi%ve closure of a rela%on R, we add an edge from a to c, when there are edges from a to b and b to c But there is a path from to 4 with no edge! R = { (,2), (2,3), (3,4) } 4 (,2) & (2,3) (,3) (2,3) & (3,4) (2,4) 4 2 3 2 3 66

Transi%ve closure Informal defini%on: If there is a path from a to b, then there should be an edge from a to b in the transi%ve closure Second take of a defini%on: In order to find the transi%ve closure of a rela%on R, we add an edge from a to c, when there are edges from a to b and b to c Repeat this step un%l no new edges are added to the rela%on We will study different algorithms for determining the transi%ve closure red means added on the first repeat teal means added on the second repeat 2 3 4 67

6 degrees of separa%on The idea that everybody in the world is connected by six degrees of separa%on Where degree of separa%on means you know (or have met) somebody else Let R be a rela%on on the set of all people in the world (a,b) R if person a has met person b So six degrees of separa%on for any two people a and g means: (a,b), (b,c), (c,d), (d,e), (e,f), (f,g) are all in R Or, (a,g) R 6 68

Connec%vity rela%on R contains edges between all the nodes reachable via edge R R = R 2 contains edges between nodes that are reachable via 2 edges in R R 2 R = R 3 contains edges between nodes that are reachable via 3 edges in R R n = contains edges between nodes that are reachable via n edges in R R* contains edges between nodes that are reachable via any number of edges (i.e. via any path) in R Rephrased: R* contains all the edges between nodes a and b when is a path of length at least between a and b in R R* is the transi%ve closure of R The defini%on of a transi%ve closure is that there are edges between any nodes (a,b) that contain a path between them 69

How long are the paths in a transi%ve closure? Let R be a rela%on on set A, and let A be a set with n elements Rephrased: consider a graph G with n nodes and some number of edges Lemma : If there is a path (of length at least ) from a to b in R, then there is a path between a and b of length not exceeding n Proof prepara%on: Suppose there is a path from a to b in R Let the length of that path be m Let the path be edges (x, x ), (x, x 2 ),, (x m-, x m ) That s nodes x, x, x 2,, x m-, x m If a node exists twice in our path, then it s not a shortest path As we made no progress in our path between the two occurrences of the repeated node Thus, each node may exist at most once in the path 7

How long are the paths in a transi%ve closure? Proof by contradic%on: Assume there are more than n nodes in the path Thus, m > n Let m = n+ By the pigeonhole principle, there are n+ nodes in the path (pigeons) and they have to fit into the n nodes in the graph (pigeonholes) Thus, there must be at least one pigeonhole that has at least two pigeons Rephrased: there must be at least one node in the graph that has two occurrences in the nodes of the path Not possible, as the path would not be the shortest path Thus, it cannot be the case that m > n If there exists a path from a to b, then there is a path from a to b of at most length n 7

Finding the transi%ve closure Let M R be the zero- one matrix of the rela%on R on a set with n elements. Then the zero- one matrix of the transi%ve closure R* is: M R* = M M M M R [2] R [3] R [ n] R Nodes reachable with one application of the relation Nodes reachable with two applications of the relation Nodes reachable with n applications of the relation 72

73 Rosen, sec%on 7.4, example 7 Find the zero- one matrix of the transi%ve closure of the rela%on R given by: = M R [3] [2] * R R R R M M M M = = = = [2] R R R M M M 2 3 2 3 = [2] M R

74 Rosen, sec%on 7.4, example 7 = = M R* = = = [2] [3] R R R M M M 2 3

Transi%ve closure algorithm What we did (or rather, could have done): Compute the next matrix, where [i] i n M R Do a Boolean join with the previously computed matrix For our example: Compute [2] MR = MR MR Join that with to yield Compute M R [3] [2] Join that with MR = MR M from R above M [2] R M R [2] MR M R 75

Transi%ve closure algorithm procedure transigve_closure (M R : zero- one n n matrix) A := M R B := A for i := 2 to n begin A := A B := B A M R end { B is the zero- one matrix for R* } 76

More transi%ve closure algorithms More efficient algorithms exist, such as Warshall s algorithm We won t be studying it in this class Thus, the material on pages 53-56 won t be on the test 77

Equivalence Rela%ons Slides by A. Bloomfield 78

Introduc%on Certain combina%ons of rela%on proper%es are very useful We won t have a chance to see many applica%ons in this course In this set we will study equivalence rela%ons A rela%on that is reflexive, symmetric and transi%ve Next slide set we will study par%al orderings A rela%on that is reflexive, an%symmetric, and transi%ve The difference is whether the rela%on is symmetric or an%symmetric 79

Outline What is an equivalence rela%on Equivalence rela%on examples Related items Equivalence class Par%%ons 8

Equivalence rela%ons A rela%on on a set A is called an equivalence relagon if it is reflexive, symmetric, and transi%ve This is defini%on in the textbook Consider rela%on R = { (a,b) len(a) = len(b) } Where len(a) means the length of string a It is reflexive: len(a) = len(a) It is symmetric: if len(a) = len(b), then len(b) = len(a) It is transi%ve: if len(a) = len(b) and len(b) = len(c), then len(a) = len(c) Thus, R is a equivalence rela%on 8

Equivalence rela%on example Consider the rela%on R = { (a,b) a b (mod m) } Remember that this means that m a- b Called congruence modulo m Is it reflexive: (a,a) R means that m a- a a- a =, which is divisible by m Is it symmetric: if (a,b) R then (b,a) R (a,b) means that m a- b Or that km = a- b. Nega%ng that, we get b- a = - km Thus, m b- a, so (b,a) R Is it transi%ve: if (a,b) R and (b,c) R then (a,c) R (a,b) means that m a- b, or that km = a- b (b,c) means that m b- c, or that lm = b- c (a,c) means that m a- c, or that nm = a- c Adding these two, we get km+lm = (a- b) + (b- c) Or (k+l)m = a- c Thus, m divides a- c, where n = k+l Thus, congruence modulo m is an equivalence rela%on 82

Rosen, sec%on 7.5, ques%on Which of these rela%ons on {,, 2, 3} are equivalence rela%ons? Determine the proper%es of an equivalence rela%on that the others lack a) { (,), (,), (2,2), (3,3) } " Has all the proper%es, thus, is an equivalence rela%on b) { (,), (,2), (2,), (2,2), (2,3), (3,2), (3,3) } " Not reflexive: (,) is missing " Not transi%ve: (,2) and (2,3) are in the rela%on, but not (,3) c) { (,), (,), (,2), (2,), (2,2), (3,3) } " Has all the proper%es, thus, is an equivalence rela%on d) { (,), (,), (,3), (2,2), (2,3), (3,), (3,2) (3,3) } " Not transi%ve: (,3) and (3,2) are in the rela%on, but not (,2) e) { (,), (,) (,2), (,), (,), (,2), (2,), (2,2), (3,3) } " Not symmetric: (,2) is present, but not (2,) " Not transi%ve: (2,) and (,) are in the rela%on, but not (2,) 83

Rosen, sec%on 7.5, ques%on 5 Suppose that A is a non- empty set, and f is a func%on that has A as its domain. Let R be the rela%on on A consis%ng of all ordered pairs (x,y) where f(x) = f(y) Meaning that x and y are related if and only if f(x) = f(y) Show that R is an equivalence rela%on on A Reflexivity: f(x) = f(x) True, as given the same input, a func%on always produces the same output Symmetry: if f(x) = f(y) then f(y) = f(x) True, by the defini%on of equality Transi%vity: if f(x) = f(y) and f(y) = f(z) then f(x) = f(z) True, by the defini%on of equality 84

Rosen, sec%on 7.5, ques%on 8 Show that the rela%on R, consis%ng of all pairs (x,y) where x and y are bit strings of length three or more that agree except perhaps in their first three bits, is an equivalence rela%on on the set of all bit strings Let f(x) = the bit string formed by the last n- 3 bits of the bit string x (where n is the length of the string) Thus, we want to show: let R be the rela%on on A consis%ng of all ordered pairs (x,y) where f(x) = f(y) This has been shown in ques%on 5 on the previous slide 85

Equivalence classes Let R be an equivalence rela%on 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 When only one rela%on is under considera%on, the subscript is o{en deleted, and [a] is used to denote the equivalence class Note that these classes are disjoint! As the equivalence rela%on is symmetric This is defini%on 2 in the textbook 86

More on equivalence classes Consider the rela%on R = { (a,b) a mod 2 = b mod 2 } Thus, all the even numbers are related to each other As are the odd numbers The even numbers form an equivalence class As do the odd numbers The equivalence class for the even numbers is denoted by [2] (or [4], or [784], etc.) [2] = {, - 4, - 2,, 2, 4, } 2 is a representagve of it s equivalence class There are only 2 equivalence classes formed by this equivalence rela%on 87

More on equivalence classes Consider the rela%on R = { (a,b) a = b or a = - b } Thus, every number is related to addi%ve inverse The equivalence class for an integer a: [7] = { 7, - 7 } [] = { } [a] = { a, - a } There are an infinite number of equivalence classes formed by this equivalence rela%on 88

Par%%ons Consider the rela%on R = { (a,b) a mod 2 = b mod 2 } This splits the integers into two equivalence classes: even numbers and odd numbers Those two sets together form a par%%on of the integers Formally, a par%%on of a set S is a collec%on of non- empty disjoint subsets of S whose union is S In this example, the par%%on is { [], [] } Or { {, - 3, -,, 3, }, {, - 4, - 2,, 2, 4, } } 89

Rosen, sec%on 7.5, ques%on 32 Which of the following are par%%ons of the set of integers? a) The set of even integers and the set of odd integers " Yes, it s a valid par%%on b) The set of posi%ve integers and the set of nega%ve integers " No: is in neither set c) The set of integers divisible by 3, the set of integers leaving a remainder of when divided by 3, and the set of integers leaving a remaineder of 2 when divided by 3 " Yes, it s a valid par%%on d) The set of integers less than -, the set of integers with absolute value not exceeding, and the set of integers greater than " Yes, it s a valid par%%on e) The set of integers not divisible by 3, the set of even integers, and the set of integers that leave a remainder of 3 when divided by 6 " The first two sets are not disjoint (2 is in both), so it s not a valid par%%on 9

Par%al Orderings Slides by A. Bloomfield 9

Introduc%on An equivalence rela%on is a rela%on that is reflexive, symmetric, and transi%ve A par%al ordering (or par%al order) is a rela%on that is reflexive, angsymmetric, and transi%ve Recall that an%symmetric means that if (a,b) R, then (b,a) R unless b = a Thus, (a,a) is allowed to be in R But since it s reflexive, all possible (a,a) must be in R A set S with a par%al ordering R is called a pargally ordered set, or poset Denoted by (S,R) 92

Par%al ordering examples Show that is a par%al order on the set of integers It is reflexive: a a for all a Z It is an%symmetric: if a b then the only way that b a is when b = a It is transi%ve: if a b and b c, then a c Note that is the par%al ordering on the set of integers (Z, ) is the par%ally ordered set, or poset 93

Symbol usage The symbol is used to represent any rela%on when discussing par%al orders Not just the less than or equals to rela%on Can represent,,, etc Thus, a b denotes that (a,b) R The poset is (S, ) 94

Comparability The elements a and b of a poset (S, ) are called comparable if either a b or b a. Meaning if (a,b) R or (b,a) R It can t be both because is an%symmetric Unless a = b, of course If neither a b nor b a, then a and b are incomparable Meaning they are not related to each other This is defini%on 2 in the text If all elements in S are comparable, the rela%on is a total ordering 95

Comparability examples Let be the divides operator In the poset (Z +, ), are the integers 3 and 9 comparable? Yes, as 3 9 Are 7 and 5 comparable? No, as 7 5 and 5 7 Thus, as there are pairs of elements in Z + that are not comparable, the poset (Z +, ) is a par%al order 96

Comparability examples Let be the less than or equals operator In the poset (Z +, ), are the integers 3 and 9 comparable? Yes, as 3 9 Are 7 and 5 comparable? Yes, as 5 7 As all pairs of elements in Z + are comparable, the poset (Z +, ) is a total order a.k.a. totally ordered poset, linear order, chain, etc. 97

Well- ordered sets (S, ) is a well- ordered set if: (S, ) is a totally ordered poset Every non- empty subset of S has a least element Example: (Z, ) Is a total ordered poset (every element is comparable to every other element) It has no least element Thus, it is not a well- ordered set Example: (S, ) where S = {, 2, 3, 4, 5 } Is a total ordered poset (every element is comparable to every other element) Has a least element () Thus, it is a well- ordered set 98

Lexicographic ordering Consider two posets: (S, ) and (T, 2 ) We can order Cartesian products of these two posets via lexicographic ordering Let s S and s 2 S Let t T and t 2 T (s,t ) (s 2,t 2 ) if either: S s 2 s = s 2 and t 2 t 2 Lexicographic ordering is used to order dic%onaries 99

Lexicographic ordering Let S be the set of word strings (i.e. no spaces) Let T bet the set of strings with spaces Both the rela%ons are alphabe%c sor%ng We will formalize alphabe%c sor%ng later Thus, our posets are: (S, ) and (T, ) Order ( run, noun: to ) and ( set, verb: to ) As run set, the run Cartesian product comes before the set one Order ( run, noun: to ) and ( run, verb: to ) Both the first part of the Cartesian products are equal noun is first (alphabe%cally) than verb, so it is ordered first

Lexicographic ordering We can do this on more than 2- tuples (,2,3,5) (,2,4,3) When is

Lexicographic ordering Consider the two strings a a 2 a 3 a m, and b b 2 b 3 b n Here follows the formal defini%on for lexicographic ordering of strings If m = n (i.e. the strings are equal in length) (a, a 2, a 3,, a m ) (b, b 2, b 3,, b n ) using the comparisons just discussed Example: run set If m n, then let t be the minimum of m and n Then a a 2 a 3 a m, is less than b b 2 b 3 b n if and only if either of the following are true: (a, a 2, a 3,, a t ) (b, b 2, b 3,, b t ) Example: run sets (t = 3) (a, a 2, a 3,, a t ) = (b, b 2, b 3,, b t ) and m < n Example: run running 2

Hasse Diagrams Consider the graph for a finite poset ({,2,3,4}, ) When we KNOW it s a poset, we can simplify the graph 4 3 4 3 4 3 4 3 Called the Hasse diagram 2 2 2 2 3

Hasse Diagram For the poset ({,2,3,4,6,8,2}, ) 4

Maximal and Minimal elements in Posets 5

Maximum and Minimum elements 6

Not being covered The remainder of 7.6 is not being covered due to lack of %me La ces Topological sor%ng 7