Homework 2

Question 1: 10pts Consider a relation with schema $R(x,y,z,w)$ and functional dependencies $S=\{x,y\rightarrow z; ~~ z\rightarrow w; ~~ w\rightarrow x\}$

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(x,y,z,w)$ with FDs $S= \{x,y\rightarrow z; ~~ z\rightarrow w; ~~ w\rightarrow x\}$
b. $R(x,y,z,w)$ with FDs $S= \{y\rightarrow z; ~~ z\rightarrow w\}$
c. $R(x,y,z,w)$ with FDs $S= \{x,y\rightarrow z; ~~ y,z\rightarrow w; ~~ z,w\rightarrow x; ~~ x,w\rightarrow y\}$

Assume $R$ is in 1NF.

Do the following:

  1. Indicate all the 3NF violations. Describe how the FD violates 3NF.
  2. 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:

  1. Indicate all BCNF violations. Describe how the FD violates BCNF.
  2. 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:

  • Gear (brand, model, category)
  • Speaker (model, power, weight, price)
  • Microphone (model, type, frequency_range, price)
  • Instrument (model, type, material, price)

Some sample data for the relations are shown below.

Gear

brandmodelcategory
A1001speaker
A1002speaker
A1003speaker
A2004microphone
A2005microphone
A2006microphone
B1004speaker
B1005speaker
B1006speaker
B2007microphone
C1007speaker
D1008speaker
D1009speaker
D1010speaker
D3004instrument
D3005instrument
E1011speaker
E1012speaker
E1013speaker
E2001microphone
E2002microphone
E2003microphone
E3001instrument
E3002instrument
E3003instrument
F2008microphone
F2009microphone
G2010microphone
H3006instrument
H3007instrument

Speakers

model powerweight price
100128040.0021.14
100221020.4090.95
100314220.4045.78
100428040.0060.49
100532020.4060.30
100632040.0010.49
100722040.0052.10
100822081.9077.00
100922040.0060.50
101028081.9077.00
101128081.9095.90
101228040.0061.49
101330620.5052.99

Microphones

model typefreq_rng price
2001wired80-10000367.30
2002wired40-2000094.99
2003wired20-1000054.99
2004cordless20-10000110.50
2005cordless20-10000250.00
2006cordless10-20000174.00
2007wired20-10000142.90
2008wired20-10000900.00
2009cordless60-2000068.59
2010wired100-3000023.00

Instruments

model typematerial price
3001guitarwood99
3002trapcanvas239
3003trapcanvas899
3004pianowood120
3005pianoplastic120
3006guitarresin100
3007guitarwood200

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 Speakers have a power of more than 300 Watts?

b. What brands of Speakers weight less than 30.00 kg?

c. Find the model number and price of all Gear (of any type) made my brand B

d. Find the model numbers of all wood instruments

e. Brands that sell Speakers but not Instruments.

f. Find those Instruments that have the same price.

g. Find those Speakers with same power and weight. 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 Speakers relation from Q4, suppose we compute the projection $\Pi_{\textrm{power}} (\textrm{Speakers})$. What are the values of this expression as a set? As a bag? What is the mean-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.