CSE390D Notes for Wednesday, 11/20/24

Chapter 9--relations motivation...talk about history of databases...fancy table manipulation how to track person + preferred email? table of 2 columns how to add an address? extra columns for address how to add multiple addresses? extra columns--bad--not flexible--pedit story (McCarthy/fascist) 2nd table: person-id + address how to keep track of students and classes and enrollments? table for student info (with key) table for course info (with key) table for enrollment (two keys, possibily other data like S/NS) That third table is a relation. ---------------------------------------------------------------------- Definition: A relation from A to B is a subset of AxB not the same as a function (just think about the many-to-many mapping of students enrolled in courses) Definition: A relation on A is a relation from A to A example: facebook friends Relations have properties: reflexive: (a, a) in R for all a in A example: has talked to symmetric: (b, a) in R whenever (a, b) in R for all a,b in A example: facebook friends antisymmetric: example: less-than might think to say (b, a) not in R whenever (a, b) in R for all a,b in A not quite...what about reflexive (e.g., <=)? instead: whenever (a, b) in R and (b, a) in R for a, b in A, a=b transitive: whenever (a, b) in R, (b, c) in R, (a, c) in R for a,b,c in A, example: <, <=, >, >= ---------------------------------------------------------------------- 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 combined. Example Let A and B be the set of all students and the set of all courses at a school, respectively. Suppose that R1 consists of all ordered pairs (a, b), where a is a student who has taken course b, and R2 consists of all ordered pairs (a, b), where a is a student who requires course b to graduate. What are the relations: R1 U R2 courses the student has taken and has to take R1 intersect R2 required courses the student has taken R1 - R2 courses the student took that weren't required R2 - R1 required courses the student hasn't yet taken ---------------------------------------------------------------------- Definition: Let R be a relation from the set A to a set B and S a relation from B to a set C. The composite of R and S is the relation consisting of ordered pairs (a, c) where a in A, c in C, and for which there exists an element b in B such that (a, b) in R and (b, c) in S. We denote the composite of R and S by S o R. Example: (a, b) in Parent: b is a parent of a (a, b) in Sister: b is a sister of a What is Parent o Sister? parent of a sister What is Sister o Parent? aunt S o R = {(a, c) | exists b such that (a,b) in R and (b,c) in S} Example: Using the relations: Parent, Child, Brother, Sister, Sibling, Father, Mother express Uncle: b is an uncle of a Brother o Parent Cousin: b is a cousin of a Child o Sibling o Parent ---------------------------------------------------------------------- Definition Let R be a relation on the set A. The powers R^n, n = 1, 2, 3, ..., are defined recursively by: R1 = R and R^(n+1) = R^n o R Theorem: The relation R on a set A is transitive if and only if R^n is a subset of R for n = 1, 2, 3, ...
Stuart Reges
Last modified: Thu Nov 21 22:30:04 PST 2024