Question 1: 10pts Consider a relation with schema $R(a,b,c,d)$ and functional dependencies $S=\{ab\rightarrow c, c\rightarrow d, d\rightarrow a\}$
a. What are all the non-trivial FDs that follow from the given FDs?
There are many: you should restrict yourself to FDs with single attributes on the right side.
Hint – My solution has 14 nontrivial FDs (including the original 3) with single attributes on the RHS.
b. What are the superkeys of R?
c. What are candidate keys of R?
Question 2: 15pts For each of the following relation schemas and sets of FDs:
a. $R(a,b,c,d)$ with FDs $S= ab\rightarrow c, c\rightarrow d, d\rightarrow a\}$
b. $R(a,b,c,d)$ with FDs $S= b\rightarrow c, c\rightarrow d\}$
c. $R(a,b,c,d)$ with FDs $S= ab\rightarrow c, bc\rightarrow d, cd\rightarrow a, ad\rightarrow b\}$
Assume $R$ is in 1NF.
Do the following:
- Indicate all the 3NF violations. Describe how the FD violates 3NF.
- Decompose the relations, as necessary, into collections of relations that are all in 3NF.
Hint – Remember to indicate the keys of the new relations
Question 3: 15pts For each of the relation schemas and sets of FDs from Question 2:
- Indicate all BCNF violations. Describe how the FD violates BCNF.
- Decompose the relations, as necessary, into collections of relations that are all in BCNF.
Hint – Remember to indicate the keys of the new relations
Question 4: 35pts This exercise builds upon the Products schema from the last homework. Recall that the database schema consists of four relations, whose schemas are:
Product(maker, model, type)
PC(model, speed, ram, hd, price)
Laptop(model, speed, ram, hd, screen, price)
Printer(model, color, type, price)
Some sample data for the relations are shown below.
Product
maker | model | type |
---|---|---|
A | 1001 | pc |
A | 1002 | pc |
A | 1003 | pc |
A | 2004 | laptop |
A | 2005 | laptop |
A | 2006 | laptop |
B | 1004 | pc |
B | 1005 | pc |
B | 1006 | pc |
B | 2007 | laptop |
C | 1007 | pc |
D | 1008 | pc |
D | 1009 | pc |
D | 1010 | pc |
D | 3004 | printer |
D | 3005 | printer |
E | 1011 | pc |
E | 1012 | pc |
E | 1013 | pc |
E | 2001 | laptop |
E | 2002 | laptop |
E | 2003 | laptop |
E | 3001 | printer |
E | 3002 | printer |
E | 3003 | printer |
F | 2008 | laptop |
F | 2009 | laptop |
G | 2010 | laptop |
H | 3006 | printer |
H | 3007 | printer |
PC
model | speed | ram | hd | price |
---|---|---|---|---|
1001 | 2.66 | 4096 | 250 | 2114 |
1002 | 2.10 | 2048 | 250 | 995 |
1003 | 1.42 | 2048 | 80 | 478 |
1004 | 2.80 | 4096 | 250 | 649 |
1005 | 3.20 | 2048 | 250 | 630 |
1006 | 3.20 | 4096 | 320 | 1049 |
1007 | 2.20 | 4096 | 200 | 510 |
1008 | 2.20 | 8192 | 250 | 770 |
1009 | 2.20 | 4096 | 250 | 650 |
1010 | 2.80 | 8192 | 300 | 770 |
1011 | 2.80 | 8192 | 160 | 959 |
1012 | 2.80 | 4096 | 160 | 649 |
1013 | 3.06 | 2048 | 80 | 529 |
Laptop
model | speed | ram | hd | screen | price |
---|---|---|---|---|---|
2001 | 2.00 | 8192 | 240 | 20.1 | 3673 |
2002 | 3.83 | 4096 | 80 | 17.0 | 949 |
2003 | 1.80 | 2048 | 60 | 15.4 | 549 |
2004 | 2.00 | 2048 | 60 | 13.3 | 1150 |
2005 | 2.16 | 4096 | 120 | 17.0 | 2500 |
2006 | 2.00 | 8192 | 80 | 15.4 | 1700 |
2007 | 1.83 | 4096 | 120 | 13.3 | 1429 |
2008 | 1.60 | 4096 | 100 | 15.4 | 900 |
2009 | 1.60 | 2048 | 80 | 14.1 | 680 |
2010 | 2.00 | 8192 | 160 | 15.4 | 2300 |
Printer
model | color | type | price |
---|---|---|---|
3001 | True | ink-jet | 99 |
3002 | False | laser | 239 |
3003 | True | laser | 899 |
3004 | True | ink-jet | 120 |
3005 | False | laser | 120 |
3006 | True | ink-jet | 100 |
3007 | True | laser | 200 |
Write expressions of relational algebra to answer the following queries. You may use the sequence of operators notation if you wish. Show the result of your query. However, your answer should work for arbitrary data, not just this data.
a. What Laptops have a ram of more than 5000Mb?
b. What makers make PCs with a speed of at most 3Ghz?
c. Find the model number and price of all products (of any type) made my manufacturer B
d. Find the model numbers of all color laser printers
e. Find those manufacturers that sell PCs, but not Laptops.
f. Find those Printers that have the same price.
g. Find those pairs of Laptops models that have both the same speed and RAM. A pair should be listed only once; e.g., list $(i,j)$ but not $(j,i)$.
Question 5: 5pts Draw expression trees for each of your expressions of Q4 (only a-e)
Question 6: 25pts Denote answers to Q4 (only a-e) in tuple relational calculus.
Question 7: 10pts Suppose relations $R$ and $S$ have $m$ tuples and $n$ tuples respectively. Give the minimum and maximum numbers of tuples that the results of the following expressions can have:
a. $R\cup S$
b. $R\bowtie S$
c. $\sigma_C (R)\times S$, for some condition $C$
d. $\Pi_L (R)-S$, for some list of attributes $L$
Question 8: 05pts Using the Laptop relation from Q4, suppose we compute the projection $\Pi_{\textrm{speed}} (\textrm{Laptop})$. What are the values of this expression as a set? As a bag? What is the average value of tuples in this projection, when treated as a set? As a bag?
Some exercises are from Garcia-Molina, Ullman, Widom. Database Systems. 2nd Edition.
This is an individual assignment. Discussion is allowed, but students may not write submitted solutions in the presence of a group.
Cite your sources.
Submissions must be uploaded to GradeScope and marked by the due date.