Mark Allen Weiss 数据结构与算法分析 课后习题答案6.pdf

Mark Allen Weiss 数据结构与算法分析 课后习题答案6.pdf

ID:52458576

大小:30.86 KB

页数:7页

时间:2020-03-27

Mark Allen Weiss 数据结构与算法分析 课后习题答案6.pdf_第1页
Mark Allen Weiss 数据结构与算法分析 课后习题答案6.pdf_第2页
Mark Allen Weiss 数据结构与算法分析 课后习题答案6.pdf_第3页
Mark Allen Weiss 数据结构与算法分析 课后习题答案6.pdf_第4页
Mark Allen Weiss 数据结构与算法分析 课后习题答案6.pdf_第5页
资源描述:

《Mark Allen Weiss 数据结构与算法分析 课后习题答案6.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、Chapter6:PriorityQueues(Heaps)6.1Yes.Whenanelementisinserted,wecompareittothecurrentminimumandchangetheminimumifthenewelementissmaller.DeleteMinOoperationsareexpensiveinthisscheme.6.21132326754126481514129101113815149751113106.3TheresultofthreeDeleteMins,Ostartingwithbothoft

2、heheapsinExercise6.2,isasfol-lows:4465651371081271081514129111514913116.46.5Thesearesimplemodi®cationstothecodepresentedinthetextandmeantasprogrammingexercises.6.6225.Toseethis,startwithiO=1andpositionattheroot.Followthepathtowardthelastnode,doublingiOwhentakingaleftchild,an

3、ddoublingiOandaddingonewhentakingarightchild.-29-6.7(a)WeshowthatHO(NO),whichisthesumoftheheightsofnodesinacompletebinarytreeofNOnodes,isNO-bO(NO),wherebO(NO)isthenumberofonesinthebinaryrepresentationofNO.ObservethatforNO=0andNO=1,theclaimistrue.Assumethatitistrueforvaluesof

4、kOuptoandincludingNO-1.SupposetheleftandrightsubtreeshaveLOandROnodes,respectively.SincetheroothasheightOIlogNOK,wehaveHO(NO)=OIlogNOK+HO(LO)+HO(RO)=OIlogNOK+LO-bO(LO)+RO-bO(RO)=NO-1+(OIlogNOK-bO(LO)-bO(RO))Thesecondlinefollowsfromtheinductivehypothesis,andthethirdfollowsbec

5、auseLO+RO=NO-1.Nowthelastnodeinthetreeisineithertheleftsubtreeortherightsub-tree.Ifitisintheleftsubtree,thentherightsubtreeisaperfecttree,andbO(RO)=OIlogNOK-1.Further,thebinaryrepresentationofNOandLOareidentical,withtheexceptionthattheleading10inNObecomes1inLO.(Forinstance,i

6、fNO=37=100101,LO=10101.)ItisclearthattheseconddigitofNOmustbezeroifthelastnodeisintheleftsub-tree.Thusinthiscase,bO(LO)=bO(NO),andHO(NO)=NO-bO(NO)Ifthelastnodeisintherightsubtree,thenbO(LO)=OIlogNOK.ThebinaryrepresentationofROisidenticaltoNO,exceptthattheleading1isnotpresent

7、.(Forinstance,ifNO=27=101011,LO=01011.)ThusbO(RO)=bO(NO)-1,andagainHO(NO)=NO-bO(NO)(b)Runasingle-eliminationtournamentamongeightelements.Thisrequiressevencom-parisonsandgeneratesorderinginformationindicatedbythebinomialtreeshownhere.aecbgfdhTheeighthcomparisonisbetweenbOandc

8、O.IfcOislessthanbO,thenbOismadeachildofcO.Otherwise,bothcOanddOaremadechild

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。