Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 3630 Database Design and Implementation

Similar presentations


Presentation on theme: "CS 3630 Database Design and Implementation"— Presentation transcript:

1 CS 3630 Database Design and Implementation

2 Mapping Relationships between sets 1 X 2 Y 3 Z 5 W 9 A B
41 mins for S1 A B

3 How to Represent a Mapping?
(Y, 2) (W, 9) R = {(Y, 2), (W, 9)} R  A  B X Y Z W 1 2 3 5 9 A B

4 Relation A mathematical relation is a subset of a Cartesian Product.
A1  A2  A3  …  An = {(x1, x2, x3, …, xn): xi  Ai} R  A1  A2  A3  …  An

5 Example A = {2, 3, 4} B = {1, 2, 5} A  B = {(2, 1), (2, 2), (2, 5),
(3, 1), (3, 2), (3, 5), (4, 1), (4, 2), (4, 5)} R1 = {(2, 2), (2, 5) , (3, 5)} = {(x, y) | x is in A, y is in B, x <= y and x < 4}

6 A relationship between A and B
= {(x, y) | x is in A, y is in B, x <= y and x <= 3} A relationship between A and B 2 3 4 1 2 5

7 Example A = {1, 2, 3, 4} B = {2, 5} A  B = {(1, 2), (1, 5), (2, 2), (2, 5), (3, 2), (3, 5), (4, 2), (4, 5)} 1 2 3 4 5

8 Relations on Three Sets
A3 = {x, y} R2 = {(a1, a2, a3): (a1, a2, a3)  A1  A2  A3, a1 + a2 = 6, and a3 = x} = {(1, 5, x), (4, 2, x)}

9 Example A = {1, 2, 3, 4} B = {2, 5} R1 = {(a, b, c): (a, b, c)  A  B  A and a + b + c < 8} = {(1, 2, 1), (1, 2, 2), (1, 2, 3), (1, 2, 4), (1, 5, 1), (2, 2, 1), (2,2, 2), (2,2,3), (3, 2, 1), (3,2,2), (4,2,1)} R2 = {(a, b, c): (a, b, c)  A  B  A and a + c = 5} = {(1, 2, 4), (1, 5,4), (2, 2, 3), (2, 5, 3), (3, 2, 2), (3, 5, 2), (4, 2, 1), (4, 5, 1)} R3 = {(a, b, c): (a, b, c)  B  A  B and b % 2 = 0} = {(2, 2, 2), (2, 2, 5), (5, 2, 2), (5, 2, 5), (2, 4, 2), (2, 4, 5), (5, 4, 2), (5, 4, 5)}

10 Total / Partial Total: Each element in the set is related to
an element in the other set Partial: Not total 1 2 3 5 9 X Y Z w Total Partial

11 One-to-Many One element could be mapped to many elements 1 X 2 Y 3 Z 5
w 1 2 3 5 9

12 Many-to-One Many elements could be mapped to one element 1 X 2 Y 3 Z 5
w 1 2 3 5 9

13 Many-to-Many Both one-to-many and many-to-one X Y Z w 1 2 3 5 9

14 One-to-One X Y Z w 1 3 5 9

15 Infinite Sets I = {i: i is an integer} N = {n: n  I and n >= 0}
= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9…} |N| =  M = {m: m  N and m % 2 = 0} = {0, 2, 4, 6, 8, …} |M| =  M  N |M| = |N| ?

16 One-to-one Mapping From N to M n 1 2 3 . . m 2 4 6 . .
1 2 3 . . m 2 4 6 . . m = 2 * n for all n  N

17 One-to-one Mapping From M to N n = m / 2 for all m  M The formula
Not just the examples

18 One-to-One Mapping I = {i: i is an integer}
N = {n: n  I and n >=0} Y = {y | y = 3 * n, where n  N} Z = {z | z = 5 * n + 2, where n  N} Find a one-to-one mapping between Y and Z.

19 One-to-One Mapping N = {0, 1, 2, 3, 4, 5 …}
Y = {y | y = 3 * n, where n  N} Z = {z | z = 5 * n + 2, where n  N} Show some elements in order: N Y Z

20 A Mapping between Y and Z
From Y to Z y = 3 * n ==> n = y / 3 z = 5 * n + 2 ==> z = 5 * (y / 3) + 2 From Z to Y y = (z – 2) * 3 / 5 Need Formula, not just examples. Does not contain n any more! Double checking!

21 Countable Sets I = {i: i is an integer} N = {n: n  I and n >= 0}
M = {m: m  N and m % 2 = 0} M  N |M| = |N| =  M  N  I |I| = |M| = |N|

22 Countable Sets I = {i: i is an integer} N = {n: n  I and n >= 0}
X = N  N = {(0, 0), (0, 1), (0, 2), … (1, 0), (1, 1), (1, 2), … (2, 0), (2, 1), (2, 2), … . . .} |X| = |N|?

23 Uncountable Sets Any example? Sets of Higher Cardinality
Any way to construct a set with a higher cardinality?

24 Assignment 1 Due Wednesday (week 2), February 1 at noon
Download a copy of the assignment and re-name it as UserName_A1.doc(x) For example, YangQ_A1.doc Complete the assignment and drop it to K:\Courses\CSSE\yangq\CS3630\1DropBox


Download ppt "CS 3630 Database Design and Implementation"

Similar presentations


Ads by Google