1 Section 4.1 Properties of Binary Relations A binary relation R over a set A is a subset of A  A. If (x, y)  R we also write x R y. Example. Some sample.

Slides:



Advertisements
Similar presentations
Representing Relations
Advertisements

1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 19 Prof. Erik Demaine.
Representing Relations Rosen 7.3. Using Matrices For finite sets we can use zero-one matrices. Elements of each set A and B must be listed in some particular.
CSE115/ENGR160 Discrete Mathematics 04/26/12 Ming-Hsuan Yang UC Merced 1.
8.3 Representing Relations Connection Matrices Let R be a relation from A = {a 1, a 2,..., a m } to B = {b 1, b 2,..., b n }. Definition: A n m  n connection.
1 Section 7.3 Representing relations (part 1: matrices)
Reachability as Transitive Closure
Lecture 17 Path Algebra Matrix multiplication of adjacency matrices of directed graphs give important information about the graphs. Manipulating these.
1 Chapter Equivalence, Order, and Inductive Proof.
 2004 SDU Lecture11- All-pairs shortest paths. Dynamic programming Comparing to divide-and-conquer 1.Both partition the problem into sub-problems 2.Divide-and-conquer.
Representing Relations Using Matrices
8.4 Closures of Relations. Intro Consider the following example (telephone line, bus route,…) abc d Is R, defined above on the set A={a, b, c, d}, transitive?
Design and Analysis of Algorithms - Chapter 81 Dynamic Programming Dynamic Programming is a general algorithm design technique Dynamic Programming is a.
Lecture 22: Matrix Operations and All-pair Shortest Paths II Shang-Hua Teng.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Algorithms All pairs shortest path
Chapter 9 1. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing.
Applied Discrete Mathematics Week 10: Equivalence Relations
Directed graphs Definition. A directed graph (or digraph) is a pair (V, E), where V is a finite non-empty set of vertices, and E is a set of ordered pairs.
Exam 2 Review 8.2, 8.5, 8.6, Thm. 1 for 2 roots, Thm. 2 for 1 root Theorem 1: Let c 1, c 2 be elements of the real numbers. Suppose r 2 -c 1.
Exam 2 Review 7.5, 7.6, |A1  A2  A3| =∑|Ai| - ∑|Ai ∩ Aj| + |A1∩ A2 ∩ A3| |A1  A2  A3  A4| =∑|Ai| - ∑|Ai ∩ Aj| + ∑ |Ai∩ Aj ∩ Ak| - |A1∩
Chapter 2 Graph Algorithms.
Properties of Relations In many applications to computer science and applied mathematics, we deal with relations on a set A rather than relations from.
Chapter 9. Chapter Summary Relations and Their Properties Representing Relations Equivalence Relations Partial Orderings.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
931102fuzzy set theory chap07.ppt1 Fuzzy relations Fuzzy sets defined on universal sets which are Cartesian products.
Discrete Math for CS Binary Relation: A binary relation between sets A and B is a subset of the Cartesian Product A x B. If A = B we say that the relation.
Chapter 9. Section 9.1 Binary Relations Definition: A binary relation R from a set A to a set B is a subset R ⊆ A × B. Example: Let A = { 0, 1,2 } and.
CSC-2259 Discrete Structures
8.3 Representing Relations Directed Graphs –Vertex –Arc (directed edge) –Initial vertex –Terminal vertex.
1 Closures of Relations: Transitive Closure and Partitions Sections 8.4 and 8.5.
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 8 Relations 歐亞書局.
1 The Floyd-Warshall Algorithm Andreas Klappenecker.
The all-pairs shortest path problem (APSP) input: a directed graph G = (V, E) with edge weights goal: find a minimum weight (shortest) path between every.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Relations.
Relations and their Properties
CHAPTER 3 FUZZY RELATION and COMPOSITION. 3.1 Crisp relation Product set Definition (Product set) Let A and B be two non-empty sets, the product.
Section 4.4 Properties of Relations. Order Relations Draw an arrow diagram for the relation R defined on the set {1,2,3,4} such that
1 Chapter Equivalence, Order, and Inductive Proof.
CSNB143 – Discrete Structure Topic 7 – Relations Part II.
Relation. Combining Relations Because relations from A to B are subsets of A x B, two relations from A to B can be combined in any way two sets can be.
Problem Statement How do we represent relationship between two related elements ?
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Representing Relations Using Matrices A relation between finite sets can be represented using a zero-one matrix Suppose R is a relation from A = {a 1,
Chapter Relations and Their Properties
Relations Section 9.1, 9.3—9.5 of Rosen Spring 2012
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Relations.
Chapter 8: Relations. 8.1 Relations and Their Properties Binary relations: Let A and B be any two sets. A binary relation R from A to B, written R : A.
Graph Theory. undirected graph node: a, b, c, d, e, f edge: (a, b), (a, c), (b, c), (b, e), (c, d), (c, f), (d, e), (d, f), (e, f) subgraph.
8.4 Closures of Relations Definition: The closure of a relation R with respect to property P is the relation obtained by adding the minimum number of.
1 Section 4.2 Equivalence Relations A binary relation is an equivalence relation if it has the three properties reflexive, symmetric, and transitive (RST).
Section 7.3: Representing Relations In this section, we will cover two ways to represent a relation over a finite set other than simply listing the relation.
§R1∪R2§R1∪R2 §R 1 ∩R 2 R1-R2R1-R2 2.4 Operations on Relations.
1 Closures of Relations Based on Aaron Bloomfield Modified by Longin Jan Latecki Rosen, Section 8.4.
Section 9.3. Section Summary Representing Relations using Matrices Representing Relations using Digraphs.
1 CMSC 250 Discrete Structures CMSC 250 Lecture 41 May 7, 2008.
Chapter 4 Fuzzy Graph and Relation Graph and Fuzzy Graph Graph G  (V, E) V : Set of vertices(node or element) E : Set of edges An edge is pair.
Lecture 7: Relations Dr Andrew Purkiss-Trew Cancer Research UK Mathematics for Computing.
Representing Relations
CSE115/ENGR160 Discrete Mathematics 04/28/11
Mathematical Structures for Computer Science Chapter 6
Discrete Math (2) Haiming Chen Associate Professor, PhD
Relations and Their Properties
Relations: representation and closures
Graph Operations And Representation
Advanced Algorithms Analysis and Design
Directed Graphs (Part II)
Agenda Lecture Content: Relations (Relasi)
Relations 12/7/2019.
Presentation transcript:

1 Section 4.1 Properties of Binary Relations A binary relation R over a set A is a subset of A  A. If (x, y)  R we also write x R y. Example. Some sample binary relations over A = {0, 1} are , A  A, eq = {(0, 0), (1, 1)}, less = {(0, 1)}. Definitions: Let R be a binary relation over a set A. R is reflexive means: x R x for all x  A. R is symmetric means: x R y implies y R x for all x, y  A. R is transitive means: x R y and y R z implies x R z for all x, y, z  A. R is irreflexive means: (x, x)  R for all x  A. R is antisymmetric means: x R y and y R x implies x = y for all x, y  A. Composition: If R and S are binary relations, then the composition of R and S is R ° S = {(x, z) | x R y and y S z for some y}. Example. eq ° less = less. Example/Quiz. Describe the properties that hold for the four sample relations: 1. . 2. A  A. 3. eq = {(0, 0), (1, 1)}. 4. less = {(0, 1)}. Answer: 1. symmetric, transitive, irreflexive, antisymmetric reflexive, symmetric, transitive. 3. reflexive, symmetric, transitive, antisymmetric. 4. irreflexive, transitive, antisymmetric. Quiz. 1. R °  = ? 2. isMotherOf ° isFatherOf = ? 3. isSonOf ° isSiblingOf = ? Answer. 1. . 2. IsPaternalGrandmotherOf. 3. isNephewOf.

2 Example (digraph representations). Let R = {(a, b), (b, a), (b, c)} over A = {a, b, c}. Then R, R 2 = R ° R, and R 3 = R 2 ° R can be represented by the following directed graphs: Closures. The closure of R with respect to a property is the smallest binary relation containing R that satisfies the property. We have the following three notations and results. The reflexive closure of R is r(R) = R  Eq, where Eq is the equality relation on A. The symmetric closure of R is s(R) = R  R c, where R c = {(b, a) | a R b}. The transitive closure of R is t(R) = R  R 2  R 3  …. Note: If | A | = n, then t(R) = R  R 2  …  R n. Example. R = {(a, b), (b, a), (b, c)} over A = {a, b, c}. Calculate the three closures of R. R2:R2: a b c R:R: R3:R3: t(R)= R  R 2  R 3 = {(a, b), (b, a), (b, c), (a, a), (b, b), (a, c)}. a b cr(R): a b cs(R): a b ct(R): r(R) = R  Eq = {(a, b), (b, a), (b, c), (a, a), (b, b), (c, c)}. s(R) = R  R c = {(a, b), (b, a), (b, c), (c, b)}.

3 Quiz (3 minutes). Let R = {(x, x + 1) | x  Z}. Find t(R), rt(R), and st(R). M = Path Problem (Is there a path from i to j?) Let R = {(1, 2), (2, 3), (3, 4)}. We can represent R as an adjacency matrix M where M ij is 1 if i R j and 0 otherwise. If we want an answer to our question, it would be nice to have the adjacency matrix for t(R). Then we could simply check whether M ij = 1. Warshall’s algorithm computes the matrix for t(R). It constructs edge (i, j) if it finds edges (i, k) and (k, j), as pictured. k ij Solution:t(R) is < rt(R) is ≤ st(R) is ≠. Example. The following trace shows M after each k-loop, where the rightmost M contains the adjacency matrix of t(R). k = 1 (no change)  k = 2 M 13 := (M 12 = M 23 = 1)  k = 3 M 14 := (M 13 = M 34 = 1) M 24 := (M 23 = M 34 = 1)  k = 4 (no change) for k := 1 to n for i := 1 to n for j := 1 to n do if M ik = M kj = 1 then M ij := 1.

4 Path Problem (What is the length of the shortest path from i to j? ) Suppose we have nonnegative weights assigned to each edge. Modify the adjacency matrix M so that M ij is the weight on edge (i, j), M ii = 0, and all other entries are . Example. Example. The following trace shows M after each k-loop, where the rightmost M contains t(R) and shortest path lengths. Floyd’s algorithm computes t(R) and the lengths of the shortest paths. for k := 1 to n for i := 1 to n for j := 1 to n do M ij := min{M ij, M ik + M kj } M = k = 1 no change  k = 2 M 14 := min{M 14, M 12 +M 24 }  k = 3 M 14 := min{M 14, M 13 +M 34 }  k = 4 no change

5 Path Problem (What is a shortest path from i to j? ) Modify Floyd by adding a path matrix P, where P ij = 0 means edge (i, j) is the shortest path from i to j (if M ij ≠  ), and P ij = k means a shortest path from i to j passes through k. Floyd’s modified algorithm computes t(R), shortest path length, and the shortest path information P. (P is initalized to all zeros.) for k := 1 to n for i := 1 to n for j := 1 to n do if M ik + M kj < M ij then M ij := M ik + M kj ; P ij := k fi Example. For the previous example, the following trace shows M and P after each k-loop. M M  P P  k = 4 no change   k = 1 no change   k = 2 M 14 := M 12 +M 24 P 14 := 2   k = 3 M 14 := M 13 +M 34 P 14 := 3

6 Quiz (2 minutes). Use your wits to find a P matrix for the pictured graph Answer. Eitheror Answer. Either or Quiz (2 minutes). Use your wits to find a P matrix for the pictured graph. Quiz (3 minutes). How many possible P matrices for the pictured graph? Answer. Where x  {2, 3}, y  {2, 3, 4} and z  {3, 4}. So there are 12 possible P matrices.