Optimal Binary Search Tree课件.ppt

  1. 1、本文档共25页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Optimal Binary Search Tree课件

Optimal Binary Search Tree;1.Preface;2.Premise;3.Formula Prove;Because we have probabilities of searches for each key and each dummy key, we can determine the expected cost of a search in a given binary search tree T. Let us assume that the actual cost of a search is the number of nodes examined, i.e., the depth of the node found by the search in T,plus1. Then the expected cost of a search in T is : (The second statement) E[ search cost in T] = (i=1~n) ∑ pi .(depthT(ki)+1) + (i=0~n) ∑ qi .(depthT(di)+1) =1 + (i=1~n) ∑ pi .depthT(ki) + (i=0~n) ∑ qi .depthT(di) Where depthT denotes a node’s depth in the tree T. ;k2;By Figure (a), we can calculate the expected search cost node by node: ;And the total cost = (0.30 + 0.10 + 0.15 + 0.20 + 0.60 + 0.15 + 0.30 + 0.20 + 0.20 + 0.20 + 0.40 ) = 2.80 So Figure (a) costs 2.80 ,on another, the Figure (b) costs 2.75, and that tree is really optimal. We can see the height of (b) is more than (a) , and the key k5 has the greatest search probability of any key, yet the root of the OBST shown is k2.(The lowest expected cost of any BST with k5 at the root is 2.85) ;Step1:The structure of an OBST;We need to use the optimal substructure to show that we can construct an optimal solution to the problem from optimal solutions to subproblems. Given keys ki ,…, kj, one of these keys, say kr (I ≦r ≦j), will be the root of an optimal subtree containing these keys. The left subtree of the root kr will contain the keys (ki ,…, kr-1) and the dummy keys( di-1 ,…, dr-1), and the right subtree will contain the keys (kr+1 ,…, kj) and the dummy keys( dr ,…, dj). As long as we examine all candidate roots kr, where I ≦r ≦j, and we determine all optimal binary search trees containing ki ,…, kr-1 and those containing kr+1 ,…, kj , we are guaranteed that we will find an OBST.;There is one detail worth nothing about “empty” subtrees. Suppose that in a subtree with keys ki,...,kj, we select ki as the root. By the above argument, ki ‘s left

文档评论(0)

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

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

1亿VIP精品文档

相关文档