09. Relations

# 09. Relations - Maggie Johnson CS103B Handout#9 Relations...

This preview shows pages 1–3. Sign up to view the full content.

Maggie Johnson Handout #9 CS103B Relations Key topics: * Introduction and Definitions * Graphs and Relations * Properties of Relations * Equivalence Relations * Partial Orderings * Composition of Relations * Matrix Representation * Closures * Topological Sorting * PERT and CPM; Scheduling Suppose we have a set of Greek deities: G = { Zeus, Apollo, Cronus, Poseidon } As everyone knows, Zeus is the father of Apollo, Cronus is the father of Poseidon, and Cronus is also the father of Zeus. It seems that there exists some combination of the elements of G that satisfy the "is the father of" relation. To express this more precisely: A relation R between two sets A and B is a subset of A X B . In other words, A X B produces a set of ordered pairs < a , b >, a coming from set A , and b from set B . Some of these pairs will be "interesting", i.e., will satisfy our relation. For these pairs, we can write a R b , where R is the symbol for our relation. Alternatively, we can write < a , b > R . (Note that R is a generic relation symbol. Some relations, such as "less-than" have their own symbol: <.) To be precise, what we have defined is a binary relation , so called because it operates on ordered pairs. We can also define unary relations, which operate on single elements, or ternary relations, which operate on ordered triples. In general an n-ary relation will operate on n-tuples. Example 1 Let's consider the “is the father of” relation (which we will denote by F ) on the set G X G . We can figure out that G X G = { <Zeus, Zeus>, <Zeus, Apollo>, <Zeus, Cronus>, <Zeus, Poseidon>, <Apollo, Zeus>, <Apollo, Apollo>, <Apollo, Cronus>, <Apollo, Poseidon>, <Cronus, Zeus>, <Cronus, Apollo>, <Cronus, Cronus>, <Cronus, Poseidon>, <Poseidon, Zeus>, <Poseidon, Apollo>, <Poseidon, Cronus>, <Poseidon, Poseidon> }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
But of the set G X G , only a subset satisfies the "is the father of" relation. Thus, applying the F relation to G X G . yields the set: { <Zeus, Apollo>, <Cronus, Poseidon>, <Cronus, Zeus> } meaning that Zeus F Apollo, Cronus F Poseidon, and Cronus F Zeus. Graphs and Relations Graphs are a general representation for expressing many-to-many relationships. The easiest way to understand the definition of a graph is to look at a picture. The following are all examples of graphs: Intuitively, we get the idea that a graph is a bunch of points connected by lines. The formal definition conveys this concept a bit more obtusely: A graph is an ordered triple < N , A , f > where N is a nonempty set of nodes or vertices (dots) A is a set of arcs or edges (lines) f is a function associating each arc a with an un ordered pair x , y of nodes called the endpoints of a . Graphs are incredibly useful structures, and the first use we will put them to is to represent the family relation described by the “father of” relation. C r o n u s Z e u s P o s e i d o n A p o l l o The astute reader may note that this graph has arrows rather than lines connecting the nodes. That is because the graph above is actually a special type of graph called a directed graph.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 20

09. Relations - Maggie Johnson CS103B Handout#9 Relations...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online