Homework 2

Question 1: 10pts Consider a relation with schema $R(a,b,c,d)$ and functional dependencies $S=\{a,b\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= \{a,b\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= \{a,b\rightarrow c; ~~ b,c\rightarrow d; ~~ c,d\rightarrow a; ~~ a,d\rightarrow b\}$

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 job board and hiring system from the last homework. Recall that the database schema consists of several relations. Let’s pick four main ones:

  • Posting(company, id, category)
  • FullTime(id, salary, hours, bonus)
  • Internship(id, type, duration, pay_per_mo)
  • Contract(id, type, location, pay)

Some sample data for the relations are shown below.

Posting

companyidcategory
Apple1001fulltime
Apple1002fulltime
Apple1003fulltime
Apple2004contract
Apple2005contract
Apple2006contract
IBM1004fulltime
IBM1005fulltime
IBM1006fulltime
IBM2007contract
Citadel1007fulltime
Dell1008fulltime
Dell1009fulltime
Dell1010fulltime
Dell3004internship
Dell3005internship
Ebay1011fulltime
Ebay1012fulltime
Ebay1013fulltime
Ebay2001contract
Ebay2002contract
Ebay2003contract
Ebay3001internship
Ebay3002internship
Ebay3003internship
Ford2008contract
Ford2009contract
Google2010contract
Hilton3006internship
Hilton3007internship

FullTime

idsalaryhoursbonus
10011280004021%
10021210002090%
10031142002045%
10041280004060%
10051320002060%
10061320004010%
10071220004052%
10081220008177%
10091220004060%
10101280008177%
10111280008195%
10121280004061%
10131306002052%

Contract

idtypelocationpay
2001onlineusa367.30
2002onlineusa94.99
2003onlineanywhere54.99
2004in persontallahassee110.50
2005in personalbany250.00
2006in personsacramento174.00
2007onlineanywhere142.90
2008onlineanywhere900.00
2009in personchicago68.59
2010in personsacramento23.00

Internship

idtypedurationpay_per_mo
3001online1 month1990
3002hybrid2 months2390
3003hybrid2 months8990
3004in person1 month2120
3005in person3 months2120
3006online4 months2100
3007online1 month2000

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 FullTime jobs have a salary of more than $130,000?

b. What companies have FullTime jobs requiring fewer than 30 hours?

c. Find the ID and compensation of all job posts (of any category) posted by IBM.

d. Find the IDs of all Internships with a duration of 1 month.

e. Find the companies that post FullTime jobs, but do not post Internships

f. Find those Internships that have the same pay_per_mo

g. Find those FullTime jobs with the same salary and number of hours. A pair of jobs 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 FullTime relation from Q4, suppose we compute the projection $\Pi_{\textrm{salary}} (\textrm{FullTime})$. 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.