码迷,mamicode.com
首页 > 其他好文 > 详细

ITA 15.5 Optimal binary search trees

时间:2016-08-27 14:09:16      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

p400 页最后一段

When j >= i , we need to select a root kr from among ki ... kj and then make an optimal binary search tree with keys ki ... kr-1 as its left subtree and an optimal binary search tree with keys kr+1 ... kj as its right subtree.What happens to the expected search cost of a subtree when it becomes a subtree of a node? (这里的subtree指的是ki ... kr-1构成的left subtree或kr+1 ... kj构成的right subtree) The depth of each node in the subtree increases by 1. By equation (15.11), the expected search cost of this subtree increases by the sum of all the probabilities in the subtree.

在计算以kr为root的tree的E[search cost in T]的时候

E[search cost in T] = e[i, j],包括3部分

  1. kr是root,depth为1,贡献pr
  2. 对于以ki ... kr-1构成的left subtree,ki ... kr-1这些节点以及叶子节点的depth都加1,根据公式15.11第一行,贡献e[i,r-1] + w(i,r-1)
  3. 对于以kr+1 ... kj构成的right subtree,kr+1 ... kj这些节点以及叶子节点的depth都加1,根据公式15.11第一行,贡献e[r+1,j] + w(r+1,j)

所以

e[i,j] = pr + e[i,r-1] + w(i,r-1) + e[r+1,j] + w(r+1,j)

 

ITA 15.5 Optimal binary search trees

标签:

原文地址:http://www.cnblogs.com/patrickzhou/p/5812856.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!