Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relations and their Properties

Similar presentations


Presentation on theme: "Relations and their Properties"— Presentation transcript:

1 Relations and their Properties
Section 9.1 Relations and their Properties

2 Binary Relation from A to B
Let A and B be sets. A binary relation from A to B is a subset of A x B. Binary because there are two sets.

3 Example Let A = { a, b, c } and B = { x, y } then
A x B = {(a,x), (a,y), (b,x), (b,y), (c,x), (c,y)} Any subset of A x B is a relation from A to B. Therefore let, for example: R1 = {(a,x), (c,y)} R2 = {(a,y), (b,x)} ¿How many relations from A to B are there? 2^(|A|*|B|)

4 Binary Relation from A to B.
A binary relation from A to B is a set R of ordered pairs where the first element of each ordered pair comes from A and the second element comes from B. aRb denotes that (a,b) is an element of R and aRb indicates that (a,b) is not an element of R. When (a,b) belongs to R then a is related to b by R.

5 Example Let: R1 = { (a,x), (c,y) } R2 = { (a,y), (b,x) } Notation
a R1 x b R1 x b R2 x

6 Depicting Relations Directed Graphs Tables Example:
Suppose A = {0, 1, 2} and B = {a, b}. Let R be the relation on A x B defined as: {(0, a), (0, b), (1, a), (2, b)} Diagrams on next slide

7

8 Functions as Relations
A function is a relation from A to B such that every element in A is the first element of exactly one ordered pair of R.

9 Relations on a Set A relation on the set A is a relation from A to A.
A relation on the set A is a subset of AxA

10 How Many Relations? If |A| = n then |AxA| = n2 . Since a relation is a subset of AxA then the number of possible relations is

11 Reflexive Relations Consider the following relations on the set {1,2,3,4} {(2,2),(2,3),(2,4),(3,2),(3,3),(3,4)} {(1,1),(1,2),(2,1),(2,2),(3,3),(4,4)} {(2,4),(4,2)} Which ones are reflexive? {(1,2),(2,3),(3,4)} {(1,1),(2,2),(3,3),(4,4)} {(1,3),(1,4),(2,3),(2,4),(3,1),(3,4)}

12 Symmetric Relations Consider the following relations on the set {1,2,3,4} {(2,2),(2,3),(2,4),(3,2),(3,3),(3,4)} {(1,1),(1,2),(2,1),(2,2),(3,3),(4,4)} 3 and 5. How could we make the others symmetric? {(2,4),(4,2)} {(1,2),(2,3),(3,4)} {(1,1),(2,2),(3,3),(4,4)} {(1,3),(1,4),(2,3),(2,4),(3,1),(3,4)}

13 Antisymmetric Relations
Consider the following relations on the set {1,2,3,4} {(2,2),(2,3),(2,4),(3,2),(3,3),(3,4)} {(1,1),(1,2),(2,1),(2,2),(3,3),(4,4)} {(2,4),(4,2)} Two elements are mutually related only if they’re equal. 4 and 5. How could we make the others antisymmetric? {(1,2),(2,3),(3,4)} {(1,1),(2,2),(3,3),(4,4)} {(1,3),(1,4),(2,3),(2,4),(3,1),(3,4)}

14 Examples Anther way to define antisymmetry:
The relation ≤ on the real numbers is antisymmetric The relation ⊆ on sets is antisymmetric The equality relation, =, on the real numbers is both symnmetric and antisymmetric (antisymmetric ≠ asymmetric!) Anther way to define antisymmetry: aRb ∧a≠b →¬(bRa)

15 Transitive Relations Consider the following relations on the set {1,2,3,4} {(2,2),(2,3),(2,4),(3,2),(3,3),(3,4)} {(1,1),(1,2),(2,1),(2,2),(3,3),(4,4)} {(2,4),(4,2)} {(1,2),(2,3),(3,4)} {(1,1),(2,2),(3,3),(4,4)} {(1,3),(1,4),(2,3),(2,4),(3,1),(3,4)}

16 Composition of Relations

17 Rn

18 Transitivity

19 Section 9.2 n-ary Relations

20 Definition Let A1, A2, … , An be sets. An n-ary relation on these sets is a subset of A1 x A2 x … x An. The sets A1, A2, … , An are called the domains of the relation, and n is called its degree.

21 Databases and Relations
Students StudentName IDnumber Major GPA Ackermann Adams Chou Goodfriend Rao Stevens 231455 888323 102147 453876 678543 786576 Computer Science Physics Mathematics Psychology 3.88 3.45 3.49 3.90 2.99 Discuss the domains and degree.

22 Operations Selection Projection Join
Chooses tuples (rows) that satisfy a condition Projection Chooses slots (columns) by position number or name Join Combines tuples from two tables with a common key Do Python Demo

23 Relational Algebra Demo
reldb.py 4 Tables: parts suppliers projects spj (a table that connects the other 3 tables)

24 Representing Relations
Section 9.3 Representing Relations

25 Using Matrices Let A = {1,2,3} and B={1,2}. Let the relation from A to B containing (a,b) if a>b. R would then equal {(2,1), (3,1), (3,2)} 1 2 3

26 Reflexive Relations

27 Symmetric SYMMETRIC NOT SYMMETRIC

28 Antisymmetric Mirror images are opposites. Diagonal is unimportant.

29 Boolean Matrices Join of Matrices Union of Relations Meet of Matrices
Intersection of Relations Examples 4-6 in 9.3 (pages ) Boolean Product of Matrices Composite Relations

30 Digraph Example a b c d V = {a,b,c,d} (b,b), (d,b), (b,d)} (a,b),
(a,d), (c,a), (c,b), E = {

31 Spotting Properties via Graphs
How can you spot the following properties from a graph? Reflexive Symmetric Antisymmetric Transitive Reflexive: every vertex has a loop. Symmetric: all non-loop mirror images are cycles (2-way) Antisymmetric: All non-loop mirror images are opposites (1-way) Transitive: not so easy! All polygonal paths are one-way complete.

32

33 Section 9.4 Closures of Relations

34 Reflexive Closure The reflexive closure of a relation, R, is the minimal relation containing R that is reflexive If R is already reflexive, it is its own reflexive closure Otherwise, add pairs (a,a) for all elements a, that are not already related to themselves. For example, if R = {(1,1), (1,2), (2,1), (3,2)}, the we add the following pairs: (2,2), (3,3).

35 Symmetric Closure The symmetric closure of a relation, R, is the minimal relation containing R that is symmetric If R is already symmetric, it is its own symmetric closure Otherwise, add pairs (b,a) for all pairs (a,b) in R that are not already there. For example, if R = {(1,1), (1,2), (2,1), (3,2)}, the we add the following pair: (2,3).

36 Can You Get There From Here?
Often we want to know if there is a “path” from a to b (meaning a chain of pairs (a,x1), (x1,x2), … (xn,b)). We say that b is “reachable in R” from a. Forming this relation is harder than it appears

37 Transitive Closure The transitive closure of a relation, R, is the minimal relation containing R that is transitive. Theorem 1: There is a path from a to b in R of length n, if and only if (a,b) ⋲ Rn. (The composition of R with itself n-1 times). R defines paths of length 1 R2 adds paths of length 2, and so on…

38 Computing the Transitive Closure
Rn computes paths of length n. This means that n+1 objects have been visited, forcing a repeat (cycle). So everything has been traversed! So all possible connected endpoints are computed by

39 Matrix Representation
M* = M v M2 v M3 v … v Mn. See Example 7 in section 9.4, page A more efficient algorithm (Warshall’s algorithm) is on page 606 (Algorithm 2 in section 9.4).

40 Equivalence Relations
Section 9.5 Equivalence Relations

41 Equivalence Relations
A relation on a set A is called an equivalence relation if it is reflexive, symmetric, and transitive.

42 Examples: Let R be the relation on the set of strings such that a R b if and only if l (a) = l (b) where l (x) is the length of x. Let R be the relation on the set of real numbers such that a R b if and only if a-b is an integer.

43 Is this an equivalence relation?
Which elements are “equivalent” (related to each other)?

44 Equivalence Classes 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. The equivalence class of a with respect to R is denoted by [a]R. When only one relation is under consideration, we will delete the subscript R and write [a] for this equivalence class.

45 [0] = {…-14, -7, 0, 7, 14, 21,…} [1] = {…-13, -6, 1, 8, 15, 22,…} [2] = {…-12, -5, 2, 9, 16, 23,…} [3] = {…-11, -4, 3, 10, 17, 24,…} [4] = {…-10, -3, 4, 11, 18, 25,…} [5] = {…-9, -2, 5, 12, 19, 26,…} [6] = {…-8, -1, 6, 13, 20, 27,…}

46

47 Partition A partition of a set S is a collection of disjoint, nonempty subsets of S that have S as their union.

48 Equivalence Relations and Partitions
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 of the set S, there is an equivalence relation R that has the sets as its equivalence classes.

49 Section 9.6 Partial Orderings

50 Partially Ordered Set (POSET)
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 a partial ordering R is called a partially ordered set, or poset, and is denoted by (S, R)

51 Example (1) Let S = {1, 2, 3} and let R = {(1,1), (2,2), (3,3), (1, 2), (3,1), (3,2)} 1 2 3 The ordering here is 3,1,2.

52 In a poset, the notation a b denotes that
This notation is used because the less than or equal to” relation is a paradigm for a partial ordering. (Note that the symbol is used to denote the relation in any poset, not just the “less than or equals” relation.) The notation a b denotes that a b, but

53 Example Let S = {1, 2, 3} and let R = {(1,1), (2,2), (3,3), (1, 2), (3,1), (3,2)} 2 2 3 2 1 2 3

54 Example (2) Consider the set of real numbers and the “less than or equal to” relation. (R, )

55 Example (3) Consider the power set of {a, b, c} and the subset relation. (P({a,b,c}), )

56 Comparable/Incomparable
The elements a and b of a poset (S, ) are called comparable if either a b or b a. When a and b are elements of S such that neither a b nor b a, a and b are called incomparable. So a and b have to appear in at least one pair.

57 Example Consider the power set of {a, b, c} and the subset relation. (P({a,b,c}), ) So, {a,c} and {a,b} are incomparable

58 Total Orders If is a poset and every two elements of S are comparable, S is called totally ordered or linearly ordered set, and is called a total order or a linear order on S. A totally ordered set is also called a chain. (S, )

59 Example Consider again, the set of real numbers and the “less than or equal to” relation. (R, )

60 Hasse Diagrams Given any partial order relation defined on a finite set, it is possible to draw the directed graph that depicts the ordering. This makes it possible to associate a somewhat simpler graph, called a Hasse diagram, with a partial order relation defined on a finite set.

61

62 Hasse Diagrams (continued)
Start with a directed graph of the relation in which all arrows point upward. Then eliminate: the loops at all the vertices, all arrows whose existence is implied by the transitive property, the direction indicators on the arrows.

63 Prerequisites Task Prerequisite Tasks Time Needed to Perform Task 1 2
3 4 5 6 7 8 9 2, 3 4, 5 6, 7, 8 7 hours 6 hours 3 hours 1 hour 2 hours 5 hours

64 Example – Job Scheduling (PERT chart)
Task 4 6 hours Task 6 1 hour Task 2 6 hours Task 1 7 hours Task 5 3 hours Task 3 3 hours Task 9 5 hour Task 8 2 hour A rotated Hasse diagram. Task 7 1 hour

65 Example (Core CNS Classes)
CNS301R CNS3520 CNS3060 CNS3690 CNS2420 CNS2600 CNS2300 CNS1410 CNS1510 CNS2810 CNS1400

66 Maximal and Minimal Elements
a is a maximal in the poset (S, ) if there is no such that a b. Similarly, an element of a poset is called minimal if it is not greater than any element of the poset. That is, a is minimal if there is no element such that b a. It is possible to have multiple minimals and maximals.

67 2 and 5 are minimal. 12, 20, and 25 are maximal.

68 Greatest Element Least Element
a is the greatest element in the poset (S, ) if b a for all Similarly, an element of a poset is called the least element if it is less than all other elements in the poset That is, a is least element if there is no such that b a.

69 min, none, max, both.

70 Job Scheduling (Again)
Task 4 6 hours Task 6 1 hour Task 2 6 hours Task 1 7 hours Task 5 3 hours Task 3 3 hours Task 9 5 hour Task 8 2 hour Pick a minimal element. Then remove it. Repeat. Copy this slide and simulate it! Task 7 1 hour How should we schedule the tasks?

71 Topological Sorting A total ordering is said to be compatible with the partial ordering R if a b whenever a R b. Constructing a total ordering from a partial ordering is called topological sorting.

72

73

74


Download ppt "Relations and their Properties"

Similar presentations


Ads by Google