Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

DDDI

Assignment #2
Normal Forms

Hongtao Ling
21/11/2023

1
Problem 1
Given a relation RpA, B, C, Dq with the FD’s AB Ñ C, C Ñ D, and D Ñ A.
1. Indicate all the BCNF violations. Do not forget to consider FD’s that are not in the
given set, but follow from them. However, it is not necessary to give violations that have
more than one attribute on the right side.
Ans :
For FD’s with one attribute on the left, we calculate A` “ A, C ` “ ACD, and
D` “ AD. Obviously, A, B, C are not the keys of R. Hence, tC Ñ Au, tC Ñ Du,
tD Ñ Au are the violations.
For FD’s with two attributes on the left, we calculate that AB ` “ R, BC ` “ R, and
BD` “ R. In addition, there is no single attribute that determines all the attributes of
R. Therefore, AB, BC, and BD are the keys of R, which will not violate BCNF when
any of them appears in the left hand. Hence, any superset of the combination of B and
any other attribute is not a BCNF violation. So, groups that violate BCNF are :
tAC Ñ Du, tAD Ñ Cu, and tCD Ñ Au.
For FD’s with three attributes on the left, ACD cannot determine B, and any triple
with B is a superkey. Hence, there is no violation.
2. Decompose the relation R, as necessary, into collections of relations that are in BCNF.
Ans :
Step 1 : pick a BCNF violation from the given dependencies. let’s start from C Ñ D.
Step 2 : compute the closure of left side attributes, namely C ` “ ACD.
Step 3 : let R1 = C ` = ACD, R2 = R ´ pC ` ´ Cq = BC.

Nonetheless, R2 is in BCNF while R1 is not in due to the existence of BCNF violation


like D Ñ A. let’s start round 2 within R1 :
Step 1 : let’s start from D Ñ A.
Step 2 : D` = AD
Step 3 : let R11 = D` = AD, R12 = R1 ´ pD` ´ Dq = CD

In sum, R can be decomposed into R11 ,R12 , and R2 while each of them keeps BCNF.

Problem 2
Let RpA, B, C, D, Eq be decomposed into relations with the following three sets of attributes :
tA, B, Cu, tB, C, Du, and tA, C, Eu.
1. For each of the following sets of FD’s, use the chase test to tell whether the decomposition
of R is lossless. For those that are not lossless, give an example of an instance of R that
returns more than R when projected onto the decomposed relations and rejoined.

2
(a) AC Ñ E and BC Ñ D.
Ans :
Let’s build an instance of R from tuple t “ abcde in πABC pRq ’ πBCD pRq ’
πACE pRq.

R A B C D E
from ABC part of t a b c d1 d e1 e
from BCD part of t a2 b c d e2
from ACE part of t a b3 c d3 e

• Use AC Ñ E to state e1 must be e


• Use BC Ñ F to state d1 must be d
Here we proved the first tuple must be t “ abcde ; then the join is lossless.
(b) A Ñ D, CD Ñ E, and E Ñ D.
Ans :
Let’s build an instance of R from tuple t “ abcde in πABC pRq ’ πBCD pRq ’
πACE pRq.

R A B C D E
from ABC part of t a b c d1 e1 e
from BCD part of t a2 b c d e2
from ACE part of t a b3 c d3 d1 e

• Use A Ñ D to state d3 must be d1


• Use CD Ñ E to state e1 must be e
• Use E Ñ D to state nothing.
here we cannot prove there is an exact t “ abcde exists in the recovery. Hence, it’s
a lossy join.
The right example is t “ abcde which exists in πABC pRq ’ πBCD pRq ’ πACE pRq
while not exists in R.
2. For each of the previous sets of FD’s, give the projected sets of FD’s onto each of the
sub-schemas ABC, BCD and ACE.
(a) Ans :
We get the projected FD by computing the closures of all the subsets of a given
sub-schema.
First of all, A` “ A, B ` “ B, C ` “ C, D` “ D, E ` “ E yield H for all the
sub-schemas tA, B, Cu, tB, C, Du, and tA, C, Eu.
For tA, B, Cu :
AB ` “ AD yields H
AC ` “ ACE yields H

3
BC ` “ BCD yields H
So, tA, B, Cu preserves no dependency.
For tB, C, Du :
BC ` “ BCD yields BC Ñ D
BD` “ BD yields H
CD` “ CF yields H
So, tB, C, Du preserves the dependency BC Ñ D
For tA, C, Eu :
AC ` “ ACE yields AC Ñ E
AE ` “ AE yields H
CE ` “ CE yields H
So, tA, C, Eu preserves the dependency AC Ñ E

(b) Ans :
We get the projected FD by computing the closures of all the subsets of a given
sub-schema.
First of all, A` “ AD, B ` “ B, C ` “ C, D` “ D, E ` “ ED yield H for all the
sub-schemas tA, B, Cu, tB, C, Du, and tA, C, Eu.
For tA, B, Cu :
AB ` “ ABD yields H
AC ` “ ACDE yields H
BC ` “ BC yields H
So, tA, B, Cu preserves no dependency.
For tB, C, Du :
BC ` “ BC yields H
BD` “ BD yields H
CD` “ CDE yields H
So, tB, C, Du preserves no dependency.
For tA, C, Eu :
AC ` “ ACDE yields AC Ñ E
AE ` “ ADE yields H
CE ` “ CDE yields H
So, tA, C, Eu preserves the dependency AC Ñ E which is a inferred dependency
of the original FDs.
3. Are dependencies preserved by the decomposition ?

(a) Ans : Yes. As illustrated in 2(a), the entire two FDs are kept in schema tB, C, Du
and tA, C, Eu, respectively.
(b) Ans : No. As illustrated in 2(b), none of the original FDs is kept on the projected
Schemas. To specify, only one inferred FD, AC Ñ E, is kept in schema tA, C, Eu.

4
Problem3
Consider the relation CoursespC, T, H, R, S, Gq, whose attributes may be thought of informally
as course, teacher, hour, room, student, and grade.
1. Translate into FD’s, when applicable, the following constraints :
(a) a course has a unique teacher ;
Ans : tC Ñ T u
(b) only one course can meet in a given room at a given hour ;
Ans : tHR Ñ Cu
(c) a teacher can be in only one room at a given hour ;
Ans : tT H Ñ Cu
(d) a student can be in only one room at a given hour ;
Ans : tHS Ñ Ru
(e) students get only one grade in a course.
Ans : tCS Ñ Gu
2. What are all the keys for Courses ?
Ans : HS ` “Courses, and H ` “ H,S ` “ S. So, HS is a key.
3. Verify that the given FD’s are their own minimal basis.
Ans :
Denote the given FD’s as F . let’s construct the minimal basis :
Step 1 : split all rhs’s. Obviously, there is no dependencies with two attribute in the
right hand. Just skip this step 1.
Step 2 : remove an FD X Ñ A and see if the remaining FD’s are equivalent to the
original. We check for each A P X w.r.t. F ´ tX Ñ Au :
• cannot remove C Ñ T , since T R CF`´tCÑT u “ C
• cannot remove HR Ñ C, since C R HRF`´tHRÑCu “ HR
• cannot remove T H Ñ C, since C R T HF`´tT HÑCu “ T H
• cannot remove HS Ñ R, since R R HSF`´tHSÑRu “ HS
• cannot remove CS Ñ G, since G R CSF`´tCSÑGu “ CT S
Define the remained dependencies as F2 , and we know F2 = F .
Step 3 : remove an attribute B from a lhs BX Ñ A. We check for each A P X w.r.t. F :
• cannot remove C in C Ñ T , since it’s singleton.
• cannot remove H or R in HR Ñ C, since H R RF`2 “ R and R R HF`2 “ H.
• cannot remove T or H in T H Ñ C, since T R HF`2 “ H and H R TF`2 “ T .
• cannot remove H or S in HS Ñ R, since H R SF`2 “ S and S R HF`2 “ H.
• cannot remove C or S in CS Ñ G, since C R SF`2 “ S and S R CT`2 “ CT .
The removal process terminates after step 3 and F2 still equals to F . Hence, the
given FD’s are their own minimal basis.

5
4. Use the 3NF synthesis algorithm to find a lossless-join, dependency-preserving decom-
position of Courses into 3NF relations. Are any of the relations not in BCNF ?
Ans :
Step 1 : Create one relation for each lhs of FD’s in the minimal cover. Schema is the
union of lhs and set of rhs’s
• R1 pCT q
• R2 pHRCq
• R3 pT HCq
• R4 pHSRq
• R5 pCSGq
Step 2 : Discard relation R(X) if S(XY) exists. No Relation is discarded here.
Step 3 : If no key is contained in an FD, then add one relation whose schema is some
key. The key of R is SH, and it is now in R4 pSHRq. Hence, No relation will be added.

In conclusion, by 3NF synthesis, We got R1 , R2 , R3 , R4 , R5 from R. Besides, they are


all in BCNF because each of them is generated from minimal cover and includes only
one dependency with the key of the relation on the left-hand side.

You might also like