1 / 15

Relations

Relations. Important Definitions . We covered all of these definitions on the board on Monday, November 7 th . Definition 1 Definition 2 Definition 3 Definition 4 Definition 5. Remember . A relation can be Symmetric and not antisymmetric R = { (1,3), (3,1)} on the set S = {1,2,3}

leroyb
Télécharger la présentation

Relations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Relations

  2. Important Definitions We covered all of these definitions on the board on Monday, November 7th. • Definition 1 • Definition 2 • Definition 3 • Definition 4 • Definition 5

  3. Remember • A relation can be • Symmetric and not antisymmetric • R = { (1,3), (3,1)} on the set S = {1,2,3} • Antisymmetric and not symmetric • R = { (1,1) (1,2) } on the set S = {1,2} • Symmetric and antisymmetric • Equality relation • Neither symmetric nor antisymmetric • R= {1,2), (2,1), (1,3)} on the set S = (1,2,3}

  4. Remember • A relation can be • Reflexive • R = { (1,1), (2,2), (3,3)} on the set S = {1,2,3} • Irreflexive • R = { (1,2), (2,3)} • Neither reflexive nor irreflexive • R1 = { (1,2), (2,1), (1,1)} on the set S= {1,2} • R2 = { (2,2) }

  5. Combining Relations • Since 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. • Union • Intersection • Set difference

  6. Composite Relations • Let R be a relation from a set A to a set B and Let S be a relation from set B to set C. • The composite of R and S is the relation consisting of the ordered pairs (a,c) where a A, c  C, and for which there exists an element b  B such that (a,b)  R & (b,c)  S • We denoted the composite of R and S by • S ° R.

  7. the Powers of a relation • The powers of a relation R can be recursively defined from the definition of a composite of two relations. • Let R be a relation on the set A. • The powers Rn, n = 1,2,3,…, are defined recursively by • R1 = R and Rn+1 = Rn°R • THEOREM: The relation R on a set A is transitive iff Rn⊆R for n = 1,2,3, …

  8. n-ARY RELATIONS • Relations among elements of more than two sets often arise. • Examples • Student: name, major, gpa • Airline flight: number, origin, destination, departure time, arrival time • Points on a line • Let A1, A2, …,An be sets. • An n-ary relation on these sets is a subset of A1 X A2X… X An

  9. Relational Database Theory • The sets A1, A2, …,An are called the domains of the relation, and n is called its degree. • The relational data model is based on the concept of a relation. • A database consists of records which are n-tuples made up of fields. • Relations used to represent database are also called tables. • Each column of the table corresponds to an attribute of the database.

  10. Database Keys • A domain of an n-ary relation is called a primary key when the value of the n-tuple from this domain determines the n-tuple. • Combinations of domains can also uniquely identify n-tuples in an n-ary relation. When the values of a set of domains determin an n-tuple in a relation, the Cartesian product of these domains is called a composite key.

  11. Operations on n-ary relations • Select • Let R be an n-ary relation and C a condition that elements in R may satisfy. Then the selection operator sC maps the n-ary relation R to the n-ary relation of all n-tuples from R that satisfy the condition C. • Project • The projection Pi1, i2, …immaps the n-tuple (a1, a2, …,an) to the m-tuple (ai1,ai2, …aim), where m <= n.

  12. Operations on n-ary relations • Join • Let R be a relation of degree m and S a relation of degree n. The join Jp (R,S), where p <= m and p <= n, is a relation of degree m+n-p that consists of all (m+n-p)-tuples (a1,a2, …,am-p, c1,c2,…,cp, b1,b2,…,bn-p), where the m-tuple (a1,a2, …,am-p, c1,c2,…,cp)belongs to R and the n-tuple (c1,c2,…,cp,,b1,b2,…,bn-p) belongs to S.

  13. Representing relations using matrices • A relation between finite sets can be represented using a zero-one matrix • Suppose that R is a relations from A = {a1, a2, …, am} to B= {b1, b2, …, bn} • The relation R can be represented by the matrix MR = [mij]where mij= 1 if (ai,bj) R, mij= 0 if (ai,bj) ∉R

  14. Representing relations using digraphs • A directed graph, or digraph, consists of a set V of vertices (or nodes) together with 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.

  15. Partial Ordering • A binary relation on a set S that is reflexive, antisymmetric, and transitive is called a partial ordering on S. • Hasse diagram • If S is finite, we can visually depict a partially ordered set by using a Hasse diagram. Each of the elements of S is represented by a dot, called a node or vertex of the diagram. If x is an immediate predecessor of y, then the node for y is placed above the node for x and the two nodes are connected by a straight line segment. • Draw the Hasse diagram for the relation “x divides y” on the set {1,2,3,6,12,18} • PERT (program evaluation and review technique) chart is a Hasse diagram with time added

More Related