《数据结构与算法分析》(C++第二版)【美】Clifford A.Shaffer著 课后习题答案 二.doc

《数据结构与算法分析》(C++第二版)【美】Clifford A.Shaffer著 课后习题答案 二.doc

ID:56721688

大小:116.00 KB

页数:28页

时间:2020-07-06

《数据结构与算法分析》(C++第二版)【美】Clifford A.Shaffer著 课后习题答案 二.doc_第1页
《数据结构与算法分析》(C++第二版)【美】Clifford A.Shaffer著 课后习题答案 二.doc_第2页
《数据结构与算法分析》(C++第二版)【美】Clifford A.Shaffer著 课后习题答案 二.doc_第3页
《数据结构与算法分析》(C++第二版)【美】Clifford A.Shaffer著 课后习题答案 二.doc_第4页
《数据结构与算法分析》(C++第二版)【美】Clifford A.Shaffer著 课后习题答案 二.doc_第5页
资源描述:

《《数据结构与算法分析》(C++第二版)【美】Clifford A.Shaffer著 课后习题答案 二.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、《数据结构与算法分析》(C++第二版)【美】CliffordA.Shaffer著课后习题答案二5BinaryTrees5.1Consideranon-fullbinarytree.Bydefinition,thistreemusthavesomeinternalnodeXwithonlyonenon-emptychild.IfwemodifythetreetoremoveX,replacingitwithitschild,themodifiedtreewillhaveahigherfractionofno

2、n-emptynodessinceonenon-emptynodeandoneemptynodehavebeenremoved.5.2Useasthebasecasethetreeofoneleafnode.Thenumberofdegree-2nodesis0,andthenumberofleavesis1.Thus,thetheoremholds.Fortheinductionhypothesis,assumethetheoremistrueforanytreewithn−1nodes.Forthei

3、nductionstep,consideratreeTwithnnodes.Removefromthetreeanyleafnode,andcalltheresultingtreeT.Bytheinductionhypothesis,Thasonemoreleafnodethanithasnodesofdegree2.Now,restoretheleafnodethatwasremovedtoformT.Therearetwopossiblecases.(1)Ifthisleafnodeistheonly

4、childofitsparentinT,thenthenumberofnodesofdegree2hasnotchanged,norhasthenumberofleafnodes.Thus,thetheoremholds.(2)IfthisleafnodeisthechildofanodeinTwithdegree2,thenthatnodehasdegree1inT.Thus,byrestoringtheleafnodeweareaddingonenewleafnodeandonenewnodeofde

5、gree2.Thus,thetheoremholds.Bymathematicalinduction,thetheoremiscorrect.32335.3BaseCase:Forthetreeofoneleafnode,I=0,E=0,n=0,sothetheoremholds.InductionHypothesis:Thetheoremholdsforthefullbinarytreecontainingninternalnodes.InductionStep:Takeanarbitrarytree(

6、callitT)ofninternalnodes.SelectsomeinternalnodexfromTthathastwoleaves,andremovethosetwoleaves.CalltheresultingtreeT’.TreeT’isfullandhasn−1internalnodes,sobytheInductionHypothesisE=I+2(n−1).Callthedepthofnodexasd.Restorethetwochildrenofx,eachatleveld+1.Weh

7、avenowaddeddtoIsincexisnowonceagainaninternalnode.Wehavenowadded2(d+1)−d=d+2toEsinceweaddedthetwoleafnodes,butlostthecontributionofxtoE.Thus,ifbeforetheadditionwehadE=I+2(n−1)(bytheinductionhypothesis),thenaftertheadditionwehaveE+d=I+d+2+2(n−1)orE=I+2nwhi

8、chiscorrect.Thus,bytheprincipleofmathematicalinduction,thetheoremiscorrect.5.4(a)templatevoidinorder(BinNode*subroot){if(subroot==NULL)return;//Empty,donothingpreorder(subroot->left());visit(subroot

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

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

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