Binary-Treesour-leafy,-annoying-friends.ppt

  1. 1、本文档共67页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Removing, Hard Case How to Remove( ) ? So Remove( ) in Partial_Map_Kernel_6 will be nontrivial to implement… But we can break down the idea into steps. You’ll need to consider the cache… Should you consider the size of the map, to know whether the cache is in the correspondence? Why or why not? You’ll need to search for the item… This must be done recursively And when you find it, you need to fix the tree The local operations Remove_Pair_From_Tree and Remove_Smallest_PFT are your friends! Think carefully about how to build them You might need one of them to build the other one… Remember: Writing Recursion The secret to writing recursive code is to only think about one level You can always assume the ensures clause works for smaller pieces of the same problem You’re only responsible for ensuring that if it works for n-1 items, it must work for n items You must handle the base case Proof is by induction on the size of problem More Practice Can’t ever get enough of tree recursion! ? global_procedure Remove_Lowest( alters Binary_Tree_Of_Item t, produces Item x); /*! requires |t| 0 ensures for all i: Item [path from root to i = path from root to x] and CONTENTS(#t) = CONTENTS(t) + x !*/ Remove_Lowest procedure_body Remove_Lowest (alters Binary_Tree_Of_Item t, produces Item x) { { object Item root; object Binary_Tree_Of_Item l, r; t.Decompose(root, l, r); if (l.Height() == 0 r.Height() == 0) { x = root; } else if l.Height() r.Height()) { Remove_Lowest(l, x); t.Compose(root, l, r); } else { Remove_Lowest(r, x); t.Compose(root, l, r); } } * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Examples of BST (of Integer)? Bad BST! No biccie. Bad BST! No biccie. Operations on BST Locating an item You should be able t

文档评论(0)

wx171113 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档