Você está na página 1de 7

CSI2132:Assignment3

MarkingGuidelines
1.
a. AminimalsetofattributeswhoseclosureincludesalltheattributesinRisakey.Sincethe
closureof{A,B},{A,B}+=R,onekeyofRis{A,B}(inthiscase,itistheonlykey).
b. To normalize R intuitively into 2NF, we take the following steps: First, identify partial
dependencies that violate 2NF. These are attributes that are functionally dependent on
either parts of the key, {A} or {B}, alone. We can calculate the closures {A}+ and {B}+ to
determinepartiallydependentattributes:
{A}+={A,D,E,I,J}.Hence{A}>{D,E,I,J}({A}>{A}isatrivialdependency)
{B}+={B,F,G,H},hence{A}>{F,G,H}({B}>{B}isatrivialdependency)
Tonormalizeinto2NF,weremovetheattributesthatarefunctionallydependentonpartof
thekey(AorB)fromRandplacetheminseparaterelationsR1andR2,alongwiththepart
ofthekeytheydependon(AorB),whicharecopiedintoeachoftheserelationsbutalso
remainsintheoriginalrelation,whichwecallR3below:
R1={A,D,E,I,J},R2={B,F,G,H},R3={A,B,C}
c. Next, to normalize R into 3NF, we look for transitive dependencies in R1, R2, R3. The
relationR1hasthetransitivedependency{A}>{D}>{I,J},soweremovethetransitively
dependent attributes {I, J} from R1 into a relation R11 and copy the attribute D they are
dependent on into R11. The remaining attributes are kept in a relation R12. Hence, R1 is
decomposedintoR11andR12asfollows:R11={D,I,J},R12={A,D,E}
The relation R2 is similarly decomposed into R21 and R22 based on the transitive
dependency{B}>{F}>{G,H}:R21={F,G,H},R22={B,F}
Thefinalsetofrelationsin3NFisasfollows:{R11,R12,R21,R22,R3}.
d. ThefinalsetofrelationsinBCNFisthesameasin3NF,R11={D,I,J},R12={A,D,E},R21=
{F,G,H},R22={B,F}andR3={A,B,C}
e. Thedecompositionislossless,sincethejoinswillnotcauseanyadditionalrowstoappear.
To test for dependency preserving, we should check whether all dependencies may be
satisfiedinonlyonerelation.Thisisindeedthecase.

2.
a) To help in solving this problem systematically, we can first find the closures of all single
attributestoseeifanyisakeyonitsownasfollows:{A}+>{A,I},{B}+>{B},{C}+>{C},
{D}+>{D},{E}+>{E},{F}+>{F},{G}+>{G},{H}+>{H,J},{I}+>{I},{J}+>{J}
Since none of the single attributes is a key, we next calculate the closures of pairs of
attributesthatarepossiblekeys:
{A,B}+>{A,B,C,I},{B,D}+>{B,D,E,F},{A,D}+>{A,D,G,H,I,J}
Noneofthesepairsarekeyseithersincenoneoftheclosuresincludesallattributes.Butthe
unionofthethreeclosuresincludesalltheattributes:
{A,B,D}+>{A,B,C,D,E,F,G,H,I}.So,{A,B,D}isakey.

b. 2NF:Thefirstlevelpartialdependenciesonthekey(whichviolate2NF)are:
{A,B}>{C,I},{B,D}>{E,F},{A,D}+>{G,H,I,J}
So,RisdecomposedintoR1,R2,R3,R4:
R1={A,B,C,I},R2={B,D,E,F},R3={A,D,G,H,I,J},R4={A,B,D}
AdditionalpartialdependenciesexistinR1andR3because{A}>{I}.
Weremove{I}intoR5,sothefollowingrelationsaretheresultof2NFdecomposition:
R1={A,B,C},R2={B,D,E,F},R3={A,D,G,H,J},R4={A,B,D},R5={A,I}

c. 3NF:Next,wecheckfortransitivedependenciesineachoftherelations(whichviolate3NF).
OnlyR3hasatransitivedependency{A,D}>{H}>{J},soitisdecomposedintoR31and
R32asfollows:R31={H,J},R32={A,D,G,H}
Thefinalsetof3NFrelationsis{R1,R2,R31,R32,R4,R5}
d.Sameasforquestion1.
e.Sameasforquestion1.

3. For this relation to be in 3NF, all of the nontrivial functional dependencies must both be fully
functionalandnontransitiveoneverykeyoftherelation.However,inthisrelationwehavetwo
dependencies (CarID Sale_date and Option_type Option_Listprice) that violate these
requirements.Bothofthesedependenciesarepartialandtransitive
4. Sinced=4,weareallowedtohave8entries.
a) SeeP.350ofthetextbook,forthealgorithm.Hereisthefinaltree.(Alsoseetheadditional
example.)

b) Thefirststepistosorttheentriesbykeyvalue;thenfollowthebulkloadingalgorithmason
p.360.
c) Seep.353ofthetextbook;hereisthefinaltree.(Alsoseetheadditionalexample.)

5. Aclusteredindexmeansthatthedatawiththesamesearchkeyislocatedneartooneanother
on disk. This may significantly increase the speed of queries as based on that key field. (See
p.277ofthetextbook.)Forexample,ifwehaveaclusteredindexonincome,thenrangequeries
basedonincomewillbefast.However,queriesbasedonanotherattributesuchasageorlevel
ofeducation,willnotbenefitfromthiskey,sotheymayactuallybesloweddown.

To practice for the Exam: Consider this case, which expands the one asked in Exercise 3. (This
question and solution has been taken from the text book Fundamentals of Database Systems, by
ElmariandNavathe.)

APARTSfilewithPart#askeyfieldincludesrecordswiththefollowingPart#values:
23,65,37,60,46,92,48,71,56,59,18,21,10,74,78,15,16,20,24,28,39,43,47,50,69,75,8,49,33,38.
1. SupposethesearchfieldvaluesareinsertedinthegivenorderinaB+treeoforderd=2;showhow
thetreewillexpandandwhatthefinaltreelookslike.
Answer:
AB+treeoforderd=2impliesthateachinternalnodeinthetree(exceptpossiblytheroot)shouldhaveat
least2keys,andatmost4..

Weshowanewtreewheninsertioncausesasplitofoneoftheleafnodes,andthenshowhowthesplit
propagatesupthetree.
Step1belowshowsthetreeafterinsertionofthefirst3keys23,65,and37,andbeforeinserting60which
causesoverflowandsplitting.Below,wegivethekeysinsertedforeachtree:
1:23,65,37;2:60;3:46;4:92;5:48,71;6:56;7:59,18;8:21;9:10;10:74;11:78;12:15;13:16;14:20;
15:24;16:28,39;17:43,47;18:50,69;19:75;20:8,49,33,38.

2. Supposethatthefollowingsearchfieldvaluesaredeleted,inthegivenorder,fromtheB+tree,
showhowthetreewillshrinkandshowthefinaltree.Thedeletedvaluesare:65,75,43,18,20,92,
59,37.


Answer:
AnimportantnoteaboutadeletionalgorithmforaB+treeisthatdeletionofakeyvaluefromaleafnode
willresultinareorganizationofthetreeif:(i)Theleafnodeislessthanhalffull;inthiscase,wewillcombine
itwiththenextleafnode(otheralgorithmscombineitwitheitherthenextorthepreviousleafnodes,or
both),(ii)Ifthekeyvaluedeletedistherightmost(last)valueintheleafnode,inwhichcaseitsvaluewill
appearinaninternalnode;inthiscase,thekeyvaluetotheleftofthedeletedkeyintheleftnodereplaces
thedeletedkeyvalueintheinternalnode.Followingiswhathappenstothetreenumber19afterthe
specifieddeletions(nottreenumber20):Deleting65willonlyaffecttheleafnode.Deleting75willcausea
leafnodetobelessthanhalffull,soitiscombinedwiththenextnode;also,75isremovedfromtheinternal
node.Deleting43causesaleafnodetobelessthanhalffull,anditiscombinedwiththenextnode.Sincethe
nextnodehas3entries,itsrightmost(first)entry46canreplace43inboththeleafandinternalnodes,
leadingtothefollowingtree:

Next,wedelete18,whichisarightmostentryinaleafnodeandhenceappearsinaninternalnodeoftheB+
tree.Theleafnodeisnowlessthanhalffull,andiscombinedwiththenextnode.Thevalue18mustalsobe
removedfromtheinternalnode,causingunderflowintheinternalnode.Oneapproachfordealingwith
underflowininternalnodesistoreorganizethevaluesoftheunderflownodewithitschildnodes,so21is
movedupintotheunderflownodeleadingtothefollowingtree:

Deleting20and92willnotcauseunderflow.Deleting59causesunderflow,andtheremainingvalue60is
combinedwiththenextleafnode.Hence,60isnolongerarightmostentryinaleafnodeandmustbe
removedfromtheinternalnode.Thisisnormallydonebymoving56uptoreplace60intheinternalnode,
butsincethisleadstounderflowinthenodethatusedtocontain56,thenodescanbereorganizedas
follows:

Finally,removing37causesseriousunderflow,leadingtoareorganizationofthewholetree.Oneapproach
todeletingthevalueintherootnodeistousetherightmostvalueinthenextleafnode(thefirstleafnodein
therightsubtree)toreplacetheroot,andmovethisleafnodetotheleftsubtree.Inthiscase,theresulting
treemaylookasfollows:

Você também pode gostar