Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 8 Relations 歐亞書局.

Slides:



Advertisements
Similar presentations
Partial Orderings Section 8.6.
Advertisements

Relations Relations on a Set. Properties of Relations.
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.
8.6 Partial Orderings. Definition Partial ordering– a relation R on a set S that is Reflexive, Antisymmetric, and Transitive Examples? R={(a,b)| a is.
Representing Relations Using Matrices
5/16/20151 You Never Escape Your… Relations. 5/16/20152Relations If we want to describe a relationship between elements of two sets A and B, we can use.
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?
Chapter 7 Relations : the second time around
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Relations.
1 Relations: The Second Time Around Chapter 7 Equivalence Classes.
1 Partial Orderings Based on Slides by Chuck Allison from Rosen, Chapter 8.6 Modified by.
Partially Ordered Sets (POSets)
Relations Chapter 9.
Chapter 9 1. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing.
Relations (3) Rosen 6th ed., ch fall.
Applied Discrete Mathematics Week 10: Equivalence Relations
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 8: Relations Relations(8.1) n-any Relations &
Chapter Relations and Their Properties 8.2 n-ary Relations and Their Applications 8.3 Representing Relations 8.4 Closures of Relations 8.5 Equivalence.
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∩
April 10, 2002Applied Discrete Mathematics Week 10: Relations 1 Counting Relations Example: How many different reflexive relations can be defined on a.
Chapter 9. Chapter Summary Relations and Their Properties Representing Relations Equivalence Relations Partial Orderings.
Discrete Structures – CNS2300
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
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.
2.6 Equivalence Relation §1.Equivalence relation §Definition 2.18: A relation R on a set A is called an equivalence relation if it is reflexive, symmetric,
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.
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Copyright  The McGraw-Hill Companies, Inc. Permission required for reproduction.
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
8.3 Representing Relations Directed Graphs –Vertex –Arc (directed edge) –Initial vertex –Terminal vertex.
Discrete Structures1 You Never Escape Your… Relations.
1 Closures of Relations: Transitive Closure and Partitions Sections 8.4 and 8.5.
Chapter 7: Relations Relations(7.1) Relations(7.1) n-any Relations & their Applications (7.2) n-any Relations & their Applications (7.2)
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Relations.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
Relations and their Properties
Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.
Fall 2002CMSC Discrete Structures1 You Never Escape Your… Relations.
Mathematical Preliminaries
Sets and Subsets Set A set is a collection of well-defined objects (elements/members). The elements of the set are said to belong to (or be contained in)
Relations. Important Definitions We covered all of these definitions on the board on Monday, November 7 th. Definition 1 Definition 2 Definition 3 Definition.
Lecture on Relations 1Developed by CSE Dept., CIST Bhopal.
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
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.
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 Partial Orderings Based on Slides by Chuck Allison from Rosen, Chapter 8.6 Modified by.
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.
Chapter8 Relations 8.1: Relations and their properties.
1 Partial Orderings Epp, section Introduction An equivalence relation is a relation that is reflexive, symmetric, and transitive A partial ordering.
Representing Relations Using Digraphs
Relations and Their Properties
Chapter 5 Relations and Operations
CSE 2813 Discrete Structures
Partial Orderings CSE 2813 Discrete Structures.
Relations Binary relations represent relationships between the elements of two sets. A binary relation R from set A to set B is defined by: R  A 
Equivalence Relations
Relations Chapter 9.
Partial Orderings.
Closures of Relations: Transitive Closure and Partitions
Discrete Math (2) Haiming Chen Associate Professor, PhD
교환 학생 프로그램 내년 1월 중순부터 6월 초 현재 학부 2,3 학년?
Relations: The Second Time Around
Presentation transcript:

Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 8 Relations 歐亞書局

8.1 Relations and Their Properties 8.2 n-ary Relations and Their Applications 8.3 Representing Relations 8.4 Closures of Relations 8.5 Equivalence Relations 8.6 Partial Orderings 歐亞書局 P. 519

8.1 Relations and Their Properties –To represent relationships between elements of sets Ordered pairs: binary relations Definition 1: Let A and B be sets. A binary relation from A to B is a subset of A  B. –a R b: (a,b)  R a is related to b by R –a b: (a,b)  R –Ex.1-3 Functions as relations –Relations are generalization of functions

FIGURE 1 (8.1) FIGURE 1 Displaying the Ordered Pairs in the Relation R from Example 3. 歐亞書局 P. 520

Relations on a Set Definition 2: a relation on the set A is a relation from A to A. –Ex.4 –Ex.5 –Ex.6: How many relations are there on a set with n elements?

FIGURE 2 (8.1) FIGURE 2 Displaying the Ordered Pairs in the Relation R from Example 4. 歐亞書局 P. 521

Properties of Relations Definition 3: A relation R on a set A is called reflexive if (a,a)  R for every element a  A. –  a((a,a)  R) –Ex.7-9 Definition 4: A relation R on a set A is called symmetric if (b,a)  R whenever (a,b)  R, for all a,b  A. A relation R on a set A such that for all a,b  A, if (a,b)  R and (b,a)  R, then a=b is called antisymmetric. –  a  b((a,b)  R →(b,a)  R) –  a  b(((a,b)  R  (b,a)  R) →(a=b)) –Not opposites –Ex

Definition 5: A relation R on a set A is called transitive if whenever (a,b)  R and (b,c)  R, then (a,c)  R, for all a,b,c  A. –  a  b  c(((a,b)  R  (b,c)  R) → (a,c)  R) –Ex

Combining Relations Two relations can be combined in any way two sets can be combined –Ex Definition 6: R: relation from A to B, S: relation from B to C. The composite of R and S is the relation consisting of ordered pairs (a,c), where a  A, c  C, and there exists an element b  B such that (a,b)  R and (b,c)  S. (denoted by S○R) –Ex.20-21

Definition 7: Let R be a relation on the set A. The powers R n, n=1,2,3,…, are defined recursively by R 1 =R, and R n+1 =R n ○R. –Ex. 22 Theorem 1: The relation R on a set A is transitive iff R n  R for n=1,2,3,… –Proof.

8.2 n-ary Relations and Their Applications To represent computer databases Definition 1: Let A 1, A 2, …, A n be sets. An n-ary relations on these sets is a subset of A 1  A 2  …  A n. The sets A 1, A 2, …, A n are called the domains of the relation, and n is called its degree. –Ex.1-4

Databases and Relations Relational data model –Records –Fields –Tables –Primary key –Ex.5-6

TABLE 1 (8.2) 歐亞書局 P. 531

Operations on n-ary Relations Definition 2: Let R be an n-ary relation and C a condition that elements in R may satisfy. Then the selection operator S C maps the n-ary relation R to the n-ary relation of all n-tuples from R that satisfy the condition C. –Ex.7 Definition 3: The projection P i1i2…im where i1<i2<…<im, maps the n-tuple (a 1,a 2,…,a n ) to the m-tuple (a i1,a i2,…,a im ), where m<=n. –Ex.8-10

TABLE 2 (8.2) 歐亞書局 P. 534

TABLE 3 (8.2) 歐亞書局 P. 534

TABLE 4 (8.2) 歐亞書局 P. 534

Definition 4: Let R be a relation of degree m and S a relation of degree n. The join J p (R,S), where p≤m and p≤n, is a relation of degree m+n-p that consists of all ( m+n-p )- tuples ( a 1,a 2,…,a m-p,c 1,c 2,…,c p,b 1,b 2,…,b n-p ), where the m -tuple ( a 1,a 2,…,a m-p,c 1,c 2,…,c p ) belongs to R and the n -tuple ( c 1,c 2,…,c p,b 1,b 2,…,b n-p ) belongs to S. –Ex.11

TABLE 5 (8.2) 歐亞書局 P. 534

TABLE 6 (8.2) 歐亞書局 P. 534

TABLE 7 (8.2) 歐亞書局 P. 535

SQL Structured Query Language –Ex.12 SELECT Departure_time FROM Flights WHERE Destination=‘Detroit’ –Ex.13 SELECT Professor, Time FROM Teaching_assignments, Class_schedule WHERE Department=‘Mathematics’

TABLE 8 (8.2) 歐亞書局 P. 535

TABLE 9 (8.2) 歐亞書局 P. 537

TABLE 10 (8.2) 歐亞書局 P. 537

8.3 Representing Relations To represent binary relations –Ordered pairs –Tables –Zero-one matrices –Directed graphs

Representing Relations Using Matrices Suppose that R is a relation from A={ a 1,a 2,…,a m } to B={ b 1,b 2,…,b n }. R can be represented by the matrix M R =[m ij ], where m ij =1 if (a i,b j )  R, or 0 if (a i,b j )  R. –Ex.1-6

FIGURE 1 (8.3) FIGURE 1 The Zero-One Matrix for a Reflexive Relation. 歐亞書局 P. 538

FIGURE 2 (8.3) FIGURE 2 The Zero-One Matrices for Symmetric and Antisymmetric Relations. 歐亞書局 P. 539

Representing Relations Using Digraphs Definition 1: A directed graph ( digraph ) consists of a set V of vertices (or nodes ) and a set E of ordered pairs of elements of V called edges (or arcs ). The vertex a is called the initial vertex of the edge (a,b), and the vertex b is called the terminal vertex of this edge. –Ex.7-10

FIGURE 3 (8.3) FIGURE 3 The Directed Graph. 歐亞書局 P. 541

FIGURE 4 (8.3) FIGURE 4 The Directed Graph of the Relations R. 歐亞書局 P. 542

FIGURE 5 (8.3) FIGURE 5 The Directed Graph of the Relations R. 歐亞書局 P. 542

FIGURE 6 (8.3) FIGURE 6 The Directed Graph of the Relations R and S. 歐亞書局 P. 542

8.4 Closures of Relations Ex. Telephone line connections Let R be a relation on a set A. R may or may not have some property P. If there is a relation S with property P containing R such that S is a subset of every relation with property P containing R, then S is called the closure of R with respect to P. –S: the smallest relation that contains R

Closures Reflexive closure –Ex: R={(1,1),(1,2),(2,1),(3,2)} on the set A={1,2,3} The smallest relation contains R? –The reflexive closure of R=R  ∆, where ∆={(a,a)|a  A} Ex.1 Symmetric closure –The symmetric closure of R=R  R -1, where R -1 ={(b,a)|(a,b)  R} Ex.2 Transitive closure –More complex

Paths in Directed Graphs Definition 1: A path from a to b in the directed graph G is a sequence of edges (x0,x1), (x1,x2), …,(xn-1,xn) in G, where n is a nonnegative integer, and x0=a and xn = b. –The path denoted by x0,x1,…,xn-1, xn has length n. –A path of length n >=1 that begins and ends at the same vertex is called a circuit or cycle. –Ex.3 –There is a path from a to b in R if there is a sequence of elements a, x1, x2, …, xn-1, b with (a,x1)  R, (x1,x2)  R, …, and (xn-1,b)  R.

FIGURE 1 (8.4) FIGURE 1 A Directed Graph. 歐亞書局 P. 546

Theorem 1: Let R be a relation on a set A. There is a path of length n, where n is a positive integer, from a to b iff (a,b)  R n. –Proof. (by mathematical induction)

Transitive Closures Definition 2: Let R be a relation on a set A. The connectivity relation R* consists of pairs (a,b) such that there is a path of length at least one from a to b in R. –R*=  n=1..  R n. –Ex.4 –Ex.5 –Ex.6

Theorem 2: The transitive closure of a relation R equals the connectivity relation R*. –Proof. Lemma 1: Let A be a set with n elements, and R be a relation on A. If there is a path of length at least one in R from a to b, then there is such as path with length not exceeding n. –When a  b, if there is a path of length at least one in R from a to b, then there is such as path with length not exceeding n-1. –Proof.

FIGURE 2 (8.4) FIGURE 2 Producing a Path with Length Not Exceeding n. 歐亞書局 P. 549

Theorem 3: Let M R be the zero-one matrix of the relation R on a set with n elements. Then the zero-one matrix of the transitive closure R* is M R* = M R  M R [2]  M R [3]  …  M R [n]. –Ex.7

Algorithm 1: A procedure for computing the transitive closure. –Procedure transitive closure ( M R : zero-one n*n matrix) A:= M R B:=A for i:=2 to n begin A:=A ๏ M R B:=B  A end –O(n 4 ) bit operations

Warshall’s Algorithm Named after Stephen Warshall in 1960 –2n 3 bit operation –Also called Roy-Warshall algorithm, Bernard Roy in 1959 Interior vertices W0, W1, …, Wn –Wk=[w ij (k) ], where w ij (k) =1 if there is a path from v i to v j such that all interior vertices of this path are in the set [v1, v2, …, vk]. –Wn= M R* –Ex.8 (Fig. 3)

FIGURE 3 (8.4) FIGURE 3 The Directed Graph of the Relations R. 歐亞書局 P. 551

Observation: we can compute Wk directly from Wk-1 –Two cases (Fig. 4) There is a path from vi to vj with its interior vertices among the first k-1 vertices –w ij (k-1) =1 There are paths from vi to vk and from vk to vj that have interior vertices only among the first k-1 vertices –w ik (k-1) =1 and w kj (k-1) =1

FIGURE 4 (8.4) FIGURE 4 Adding v k to the Set of Allowable Interior Vertices. 歐亞書局 P. 553

Lemma 2: Let Wk=w ij (k) be the zero-one matrix that has a 1 in its (i,j)th position iff there is a path from vi to vj with interior vertices from the set {v1, v2, …, vk}. Then w ij (k) =w ij (k-1)  (w ik (k-1)  w kj (k-1) ), whenever I, j, and k are positive integers not exceeding n.

Algorithm 2: Warshall Algorithm –Procedure Warshall( M R : n*n zero-one matrix) W:= M R for k:=1 to n begin for i:=1 to n begin for j:=1 to n wij:=wij  (wik  wkj) end end

8.5 Equivalence Relations Definition 1: A relation on a set A is called an equivalence relation if it is reflexive, symmetric, and transitive. Definition 2: Two elements a and b are related by an equivalence relation are called equivalent. –The notation a~b : to denote that a and b are equivalent elements with respect to a particular equivalence relation –Ex. 1-5: equivalence relations –Ex. 6-7: not equivalence relations

Equivalence Classes Definition 3: Let R be an equivalence relation 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. –Denoted by [a] R or [a] –[a] R = {s|(a,s)  R} –If b  [a] R, then b is called a representative of the equivalence class –Ex. 8-11

Equivalence Classes and Partitions Theorem 1: Let R be an equivalence relation on a set A. These statements for elements a and b of A are equivalent: –a R b –[a]=[b] –[a]  [b]   –Proof.

Observations –  a  A [a] R =A –[a]  [b]=  when [a] R  [b] R The equivalence classes form a partition of A –A partition of a set S is a collection of disjoint nonempty subsets of S that have S as their union Ai   for i  I, Ai  Aj=  when i  j  i  I Ai=S Ex.12

FIGURE 1 (8.5) FIGURE 1 A Partition of a Set. 歐亞書局 P. 561

Theorem 2: Let R be an equivalence relation on a set S. Then the equivalence classes of R form a partition of S. Conversely, given a partition {Ai|i  I} of the set S, there is an equivalence relation R that has the sets Ai, i  I, as its equivalence classes. –Ex.13-15

8.6 Partial Orderings Definition 1: A relation R on a set S is called a partial ordering or partial order if it is reflexive, antisymmetric, and transitive. –A set S together with its partial ordering R is called a partially ordered set, or poset, (S, R). –Proof. –Ex.1-3: ≥, |,  –Ex.4: older than –Notation: : a ≤ b, but a  b

Definition 2: The elements a and b of a poset (S, ) are called comparable if either a b or b a. –If neither a b nor b a, a and b are incomparable. (“partial”) –Ex. 5 –When every two elements in the set are comparable, the relation is called a total ordering

Definition 3: If (S, ) is a poset and every two elements of S are comparable, S is called a totally ordered or linearly ordered set (or a chain ), and is called a total order or a linear order. –Ex.6: ( Z, ≤) –Ex.7: ( Z +, |) Definition 4: (S, ) is a well-ordered set if it is a poset such that is a total ordering and every nonempty subset of S has a least element. –Ex.8

Theorem 1: (The Principle of Well- Ordered Induction) Suppose that S is a well-ordered set. Then P(x) is true for all x  S, if (inductive step): For every y  S, if P(x) is true for all x  S with x y, then P(y) is true. –Proof.

Lexicographic Order (A 1, 1 ), (A 2, 2 ) –(a 1, a 2 ) (b 1, b 2 ) Either if a 1 1 b 1 Or if a 1 =b 1 and a 2 2 b 2 –Ex.9-10 –n-tuples (Fig. 1) –Ex.11

FIGURE 1 (8.6) FIGURE 1 The Ordered Pairs Less Than (3,4) in Lexicographic Order. 歐亞書局 P. 570

Hasse Diagrams Hasse Diagrams: some edges do not have to be shown –Reflexive: loops can be removed –Transitive: if (a,b) and (b,c), then (a,c) can be removed –Remove all the arrows –Ex. 12: (Fig. 3) –Ex. 13: (Fig. 4)

FIGURE 2 (8.6) FIGURE 2 Constructing the Hasse Diagram for ({1,2,3,4}, ≦ ). 歐亞書局 P. 571

FIGURE 3 (8.6) FIGURE 3 Constructing the Hasse Diagram of ({1,2,3,4,6,8,12}, | ). 歐亞書局 P. 572

FIGURE 4 (8.6) 歐亞書局 P. 573 FIGURE 4 The Hasse Diagram of (P({a,b,c}), ).

Maximal and Minimal Elements a is maximal in the poset (S, ) if there is no b  S such that a b. a is minimal in the poset (S, ) if there is no b  S such that b a. –Ex. 14: (Fig. 5) –Ex. 15: (Fig. 6) –Ex

FIGURE 5 (8.6) FIGURE 5 The Hasse Diagram of a Poset. 歐亞書局 P. 573

FIGURE 6 (8.6) FIGURE 6 Hasse Diagrams of Four Posets. 歐亞書局 P. 573

In a subset A of a poset (S, ), if u is an element of S such that a u for all a  A, then u is an upper bound of A. In a subset A of a poset (S, ), if l is an element of S such that l a for all a  A, then l is an lower bound of A. –Ex. 18: (Fig. 7) –Ex. 19: (Fig. 7) –Ex. 20

FIGURE 7 (8.6) FIGURE 7 The Hasse Diagram of a Poset. 歐亞書局 P. 574

Lattices A partially ordered set in which every pair of elements has both a least upper bound and a greatest lower bound is called a lattice –Ex. 21: (Fig. 8) –Ex

FIGURE 8 (8.6) FIGURE 8 Hasse Diagrams of Three Posets. 歐亞書局 P. 575

Topological Sorting A total ordering is said to be compatible with the partial ordering R if a b whenever a R b. –Topological sorting: constructing a compatible total ordering from a partial ordering Lemma 1: Every finite nonempty poset (S, ) has at lease one minimal element.

Algorithm 1: topological sorting –Procedure topological sort(S, : finite poset) k:=1 while S   begin ak:=a minimal element of S S:=S-{ak} k:=k+1 end –Ex.26: (Fig. 9) –Ex. 27: (Fig. 10, 11)

FIGURE 9 (8.6) FIGURE 9 A Topological Sort of ({1,2,4,5,12,20}, | ). 歐亞書局 P. 577

FIGURE 10 (8.6) FIGURE 10 The Hasse Diagram for Seven Tasks. 歐亞書局 P. 578

FIGURE 11 (8.6) FIGURE 11 A Topological Sort of the Tasks. 歐亞書局 P. 578

Thanks for Your Attention!