Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 311: Foundations of Computing Fall 2014 Lecture 20: Relations and Directed Graphs.

Similar presentations


Presentation on theme: "CSE 311: Foundations of Computing Fall 2014 Lecture 20: Relations and Directed Graphs."— Presentation transcript:

1 CSE 311: Foundations of Computing Fall 2014 Lecture 20: Relations and Directed Graphs

2 Relations Let A and B be sets, A binary relation from A to B is a subset of A  B Let A be a set, A binary relation on A is a subset of A  A

3 Relations You Already Know!

4 Relation Examples R 1 = {(a, 1), (a, 2), (b, 1), (b, 3), (c, 3)} R 2 = {(x, y) | x ≡ y (mod 5) } R 3 = {(c 1, c 2 ) | c 1 is a prerequisite of c 2 } R 4 = {(s, c) | student s had taken course c }

5 Properties of Relations Let R be a relation on A. R is reflexive iff (a,a)  R for every a  A R is symmetric iff (a,b)  R implies (b, a)  R R is transitive iff (a,b)  R and (b, c)  R implies (a, c)  R

6 Combining Relations

7 Examples

8 Using the relations: Parent, Child, Brother, Sister, Sibling, Father, Mother, Husband, Wife express: Uncle: b is an uncle of a Cousin: b is a cousin of a

9 Powers of a Relation

10 Matrix Representation {(1, 1), (1, 2), (1, 4), (2,1), (2,3), (3,2), (3, 3), (4,2), (4,3)} 1234 1 1101 2 1010 3 0110 4 0110

11 Directed Graphs Path: v 0, v 1, …, v k, with (v i, v i+1 ) in E Simple Path Cycle Simple Cycle G = (V, E) V – vertices E – edges, ordered pairs of vertices

12 Representation of Relations Directed Graph Representation (Digraph) {(a, b), (a, a), (b, a), (c, a), (c, d), (c, e) (d, e) } ad e bc

13 Relational Composition using Digraphs

14 Paths in Relations and Graphs Let R be a relation on a set A. There is a path of length n from a to b if and only if (a,b)  R n A path in a graph of length n is a list of edges with vertices next to each other.

15 Connectivity In Graphs Let R be a relation on a set A. The connectivity relation R* consists of the pairs (a,b) such that there is a path from a to b in R. Note: The text uses the wrong definition of this quantity. What the text defines (ignoring k=0) is usually called R + Two vertices in a graph are connected iff there is a path between them.

16 Properties of Relations (again) Let R be a relation on A. R is reflexive iff (a,a)  R for every a  A R is symmetric iff (a,b)  R implies (b, a)  R R is transitive iff (a,b)  R and (b, c)  R implies (a, c)  R

17 Transitive-Reflexive Closure Add the minimum possible number of edges to make the relation transitive and reflexive. The transitive-reflexive closure of a relation R is the connectivity relation R*

18 how is Anderson related to Ber noul?

19

20 CSE 31120 http://genealogy.math.ndsu.nodak.edu/

21 BauerCaratheodoryMinkowski Klein LipschitzDirichletFourier LagrangeEuler Johann BernoulliJacob Bernoulli Leibniz RheticusCopernicus Anderson Weigel Mayr

22 Beame CookQuineWhiteheadHopkins SedgewickSmith NewtonBarrowGalileo

23 Nicolaus Copernicus Georg Rheticus Moritz Steinmetz Christoph Meurer Philipp Muller Erhard Weigel Gottfried Leibniz Noclas Malebranache Jacob Bernoulli Johann Bernoulli Leonhard Euler Joseph Lagrange Jean-Baptiste Fourier Gustav Dirichlet Rudolf Lipschitz Felix Klein C. L. Ferdinand Lindemann Herman Minkowski Constantin Caratheodory Georg Aumann Friedrich Bauer Manfred Paul Ernst Mayr Richard Anderson Galileo Galilei Vincenzo Viviani Issac Barrow Isaac Newton Roger Cotes Robert Smith Walter Taylor Stephen Whisson Thomas Postlethwaite Thomas Jones Adam Sedgewick William Hopkins Edward Routh Alfred North Whitehead Willard Quine Hao Wang Stephen Cook Paul Beame

24 n-ary Relations

25 Relational Databases Student_NameID_NumberOfficeGPA Knuth3280120980224.00 Von Neuman4810802205553.78 Russell2380823880223.85 Einstein2380019200222.11 Newton17270173333.61 Karp3488828110223.98 Bernoulli29219380223.21 STUDENT

26 Relational Databases Student_NameID_NumberOfficeGPACourse Knuth3280120980224.00CSE311 Knuth3280120980224.00CSE351 Von Neuman4810802205553.78CSE311 Russell2380823880223.85CSE312 Russell2380823880223.85CSE344 Russell2380823880223.85CSE351 Newton17270173333.61CSE312 Karp3488828110223.98CSE311 Karp3488828110223.98CSE312 Karp3488828110223.98CSE344 Karp3488828110223.98CSE351 Bernoulli29219380223.21CSE351 What’s not so nice? STUDENT

27 relational databases ID_NumberCourse 328012098CSE311 328012098CSE351 481080220CSE311 238082388CSE312 238082388CSE344 238082388CSE351 1727017CSE312 348882811CSE311 348882811CSE312 348882811CSE344 348882811CSE351 2921938CSE351 Better Student_NameID_NumberOfficeGPA Knuth3280120980224.00 Von Neuman4810802205553.78 Russell2380823880223.85 Einstein2380019200222.11 Newton17270173333.61 Karp3488828110223.98 Bernoulli29219380223.21 STUDENT TAKES

28 database operations: projection Office 022 555 333 OfficeGPA 0224.00 5553.78 0223.85 0222.11 3333.61 0223.98 0223.21

29 database operations: selection Find students with GPA > 3.9 : σ GPA>3.9 (STUDENT) Student_NameID_NumberOfficeGPA Knuth3280120980224.00 Karp3488828110223.98 Retrieve the name and GPA for students with GPA > 3.9: Π Student_Name,GPA (σ GPA>3.9 (STUDENT)) Student_NameGPA Knuth4.00 Karp3.98

30 database operations: natural join Student_NameID_NumberOfficeGPACourse Knuth3280120980224.00CSE311 Knuth3280120980224.00CSE351 Von Neuman4810802205553.78CSE311 Russell2380823880223.85CSE312 Russell2380823880223.85CSE344 Russell2380823880223.85CSE351 Newton17270173333.61CSE312 Karp3488828110223.98CSE311 Karp3488828110223.98CSE312 Karp3488828110223.98CSE344 Karp3488828110223.98CSE351 Bernoulli29219380223.21CSE351 Student ⋈ Takes


Download ppt "CSE 311: Foundations of Computing Fall 2014 Lecture 20: Relations and Directed Graphs."

Similar presentations


Ads by Google