0% found this document useful (0 votes)
11 views

assn4-sample-solution

Uploaded by

Safina Soomro
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

assn4-sample-solution

Uploaded by

Safina Soomro
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CS 405

Assignment 4
Sample solutions

Problem 1
a)
𝐵 + = {𝐵} (𝑆𝑡𝑎𝑟𝑡)
𝐵 + = {𝐵, 𝐷} (𝐵 → 𝐷)
b)
𝐴+ = {𝐴} (𝑆𝑡𝑎𝑟𝑡)
𝐴+ = {𝐴, 𝐵, 𝐶} (𝐴 → 𝐵𝐶)
𝐴+ = {𝐴, 𝐵, 𝐶, 𝐷} (𝐵 → 𝐷)
𝐴+ = {𝐴, 𝐵, 𝐶, 𝐷, 𝐸} (𝐶𝐷 → 𝐸)
A is a candidate key.
𝐵 + = {𝐵, 𝐷} (𝐹𝑟𝑜𝑚 𝑝𝑎𝑟𝑡 𝑎)
B is not a candidate key.
𝐶 + = {𝐶} (𝑆𝑡𝑎𝑟𝑡)
C is not a candidate key.
𝐷+ = {𝐷} (𝑆𝑡𝑎𝑟𝑡)
D is not a candidate key.
𝐸 + = {𝐸} (𝑆𝑡𝑎𝑟𝑡)
𝐸 + = {𝐴, 𝐸} (𝐸 → 𝐴)
𝐸 + = {𝐴, 𝐵, 𝐶, 𝐸} (𝐴 → 𝐵𝐶)
𝐸 + = {𝐴, 𝐵, 𝐶, 𝐷, 𝐸} (𝐵 → 𝐷)
E is a candidate key.
{𝐵, 𝐶}+ = {𝐵, 𝐶} (𝑆𝑡𝑎𝑟𝑡)
{𝐵, 𝐶}+ = {𝐵, 𝐶, 𝐷} (𝐵 → 𝐷)
{𝐵, 𝐶}+ = {𝐵, 𝐶, 𝐷, 𝐸} (𝐶𝐷 → 𝐸)
{𝐵, 𝐶}+ = {𝐴, 𝐵, 𝐶, 𝐷, 𝐸} (𝐸 → 𝐴)
{B,C} is a candidate key.
{𝐶, 𝐷}+ = {𝐶, 𝐷} (𝑆𝑡𝑎𝑟𝑡)
{𝐶, 𝐷}+ = {𝐶, 𝐷, 𝐸} (𝐶𝐷 → 𝐸)
{𝐶, 𝐷}+ = {𝐴, 𝐶, 𝐷, 𝐸} (𝐸 → 𝐴)
{𝐶, 𝐷}+ = {𝐴, 𝐵, 𝐶, 𝐷, 𝐸} (𝐴 → 𝐵𝐶)
{C,D} is a candidate key.
Our candidate keys are A, E, {B,C}, and {C,D}.

c)
We know that the relation is 1NF under all candidate keys because there are no multivalued
attributes.
We also know that the relation is 2NF because there are no non-key attributes that are partially
dependent on a set of key attributes.
We also know that the relation is 3NF because there are no non-key attributes that depend on
other non-key attributes.
However, the relation is not BCNF because B alone is not a candidate key and the function
dependency B->D exists.
The highest normal form is 3NF.

d)
The decomposition can be verified as lossless using the algorithm described on pages 554 and
555 of the textbook. The matrix S is initialized to this:
A B C D E
R1 𝑎0 𝑎1 𝑎2 𝑏03 𝑏04
R2 𝑎0 𝑏11 𝑏12 𝑎3 𝑎4

After the first iteration of the loop in step 4, the matrix will look like this:
A B C D E
R1 𝑎0 𝑎1 𝑎2 𝑏03 𝑏04
R2 𝑎0 𝑎1 𝑎2 𝑎3 𝑎4
Since R2 is made up entirely of ‘a’ symbols, the decomposition has the nonadditive join
property, meaning the decomposition is lossless.

e)
The decomposition can be verified as not lossless using the algorithm described on pages 554
and 555 of the textbook. The matrix S is initialized to this:
A B C D E
R1 𝑎0 𝑎1 𝑎2 𝑏03 𝑏04
R2 𝑏10 𝑏11 𝑎2 𝑎3 𝑎4

After one complete loop execution, the matrix will remain unchanged. Also, there are no rows
that consist of only ‘a’ elements. Because of this, the decomposition does not have the
nonadditive join property, meaning the decomposition is lossy.

Problem 2
The following sets of attributes can form keys of R:
{Course_no, Sec_no, Semester, Year}
{Room_no, Days_hours, Semester, Year}
There is some redundancy – for each semester and each section a course is offered, the offering
department, credit hours, and course level are unnecessarily reiterated. The relation can be
normalized as follows:
R1 = {Course_no, Offering_dept, Credit_hours, Course_level}
R2 = {Course_no, Sec_no, Semester, Year, Days_hours, Room_no, No_of_students,
Instructor_ssn}
Of course, this decomposition satisfies 1NF since there are no multivalued attributes. This
decomposition also satisfies 2NF since there are no non-key attributes that are partially
dependent on attributes that are part of a key. The decomposition also satisfies 3NF since all
determinants of non-key attributes are candidate keys. Finally, the decomposition is also BCNF
since all determinants are candidate keys.

Problem 3
The relation is 1NF since there are no multivalued attributes. However, the relation is not 2NF
because Commission% is partially dependent on Salesperson#. Due to this, the relation can be
decomposed as follows:
R1 = {Salesperson#, Commission%}
R2 = {Car#, Date_sold, Salesperson#, Discount_amt}
This decomposed relation is 2NF. However, this decomposed relation is not 3NF because the
determinant of Disccount_amt, a non-key attribute, is dependent on Date_sold, which is also a
non-key attribute. The relation can be further decomposed as shown below:
R1 = {Salesperson#, Commission%}
R2 = {Car#, Date_sold, Salesperson#}
R3 = {Date_sold, Discount_amt}
This decomposed relation is 3NF. It is also BNF since there are no non-key attributes that are
determinants.

Problem 4
In this problem, we are assuming that each day a patient visits a doctor, a different treatment will
be performed, yet the doctor’s diagnosis of the patient is kept constant across all visits. Based on
the description of what occurs within a visit to the doctor, the following functional dependencies
can be derived:
{Doctor#, Patient#} -> Diagnosis
{Doctor#, Patient#, Date} -> Treat_code
Treat_code -> Charge
Due to this, the only candidate key for this relation is {Doctor#, Patient#, Date}.
This relation is not 2NF. This is because there Diagnosis is partially dependent on {Doctor#,
Patient#}. Due to this, the relation can be decomposed as follows to achieve 2NF:
R1: {Doctor#, Patient#, Date, Treat_code, Charge}
R2: {Doctor#, Patient#, Diagnosis}
The above relation is 2NF. However, it is not 3NF because Charge, a non-key is dependent on
Treat_code, which is also a non-key. The relation can be further decomposed as follows:
R1: {Doctor#, Patient#, Date, Treat_code}
R2: {Doctor#, Patient#, Diagnosis}
R3: {Treat_code, Charge}

You might also like