Download presentation
Presentation is loading. Please wait.
Published byDerrick Theodore Stafford Modified over 9 years ago
1
Relations
2
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
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 R 1 = { (1,2), (2,1), (1,1)} on the set S= {1,2} R 2 = { (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 R n, n = 1,2,3,…, are defined recursively by R 1 = R and R n+1 = R n ° R THEOREM: The relation R on a set A is transitive iff R n ⊆ 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 A 1, A 2, …,A n be sets. An n-ary relation on these sets is a subset of A 1 X A 2 X… X A n
9
Relational Database Theory The sets A 1, A 2, …,A n 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 s C 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 P i1, i2, …im maps the n-tuple (a 1, a 2, …,a n ) to the m-tuple (a i1,a i2, …a im ), 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 J p (R,S), where p <= m and p <= n, is a relation of degree m+n-p that consists of all (m+n-p)-tuples (a 1,a 2, …,a m-p, c 1,c 2,…,c p, b 1,b 2,…,b n-p ), where the m-tuple (a 1,a 2, …,a m-p, c 1,c 2,…,c p ) belongs to R and the n-tuple (c 1,c 2,…,c p,,b 1,b 2,…,b n-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 M R = [m ij ] where m ij = 1 if (a i,b j ) R, m ij = 0 if (a i,b j ) ∉ 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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.