ITA 15.5 Optimal binary search trees
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部分
- kr是root,depth为1,贡献pr
- 对于以ki ... kr-1构成的left subtree,ki ... kr-1这些节点以及叶子节点的depth都加1,根据公式15.11第一行,贡献e[i,r-1] + w(i,r-1)
- 对于以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的更多相关文章
- Optimal binary search trees
问题 该问题的实际应用 Suppose that we are designing a program to translate text from English to French. For ea ...
- Method for balancing binary search trees
Method for balancing a binary search tree. A computer implemented method for balancing a binary sear ...
- LeetCode解题报告—— Unique Binary Search Trees & Binary Tree Level Order Traversal & Binary Tree Zigzag Level Order Traversal
1. Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) that ...
- 【二叉查找树】02不同的二叉查找树个数II【Unique Binary Search Trees II】
提到二叉查找树,就得想到二叉查找树的递归定义, 左子树的节点值都小于根节点,右子树的节点值都大于根节点. +++++++++++++++++++++++++++++++++++++++++++++++ ...
- 【二叉查找树】01不同的二叉查找树的个数【Unique Binary Search Trees】
当数组为1,2,3,4,...,n时,基于以下原则构建的BST树具有唯一性: 以i为根节点的树,其左子树由[1,i-1]构成,其右子树由[i+1, n]构成. 我们假定f(i)为以[1,i]能产生的U ...
- [LeetCode] Unique Binary Search Trees 独一无二的二叉搜索树
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...
- 2 Unique Binary Search Trees II_Leetcode
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...
- 【leetcode】Unique Binary Search Trees (#96)
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
随机推荐
- NKOJ3485 【2015多校联训4】数据
问题描述 Mr_H 出了一道信息学竞赛题,就是给 n 个数排序.输入格式是这样的:试题有若干组数据.每组数据的第一个是一个整数 n,表示总共有 n 个数待排序:接下来 n 个整数,分别表示这n 个待排 ...
- NOIP2016参赛日志+总结
这个故事告诉我们,成绩出来之前一定要装弱.这些文字是作者拿到程序后测了洛谷民间数据后写的. 2016.11.18 Day 0 早上五点半起床,洗漱完毕,吃了早饭,收拾收拾,七点半从家出发,去了 ...
- 洛谷P1965 转圈游戏 [2013NOIP提高组 D1T1][2017年6月计划 数论04]
P1965 转圈游戏 题目描述 n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n-1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 ...
- C++学习笔记----4.5 C++继承时的对象内存模型
推荐阅读:http://blog.csdn.net/randyjiawenjie/article/details/6693337 最近研究了一下,C++继承的内存对象模型.主要是读了读http://b ...
- input 手机数字键盘
要一点击提起数字键盘,安卓只要设置input的类型是number或tel, ios 需要 pattern="number"可以直接打开搜狗输入法的数字键盘,可以输入.和数字如果只能 ...
- PyCharm 头文件设置及作用
PyCharm 头文件 设置 进入File --->settings---->Editor---->File and Code Templates----->Python Sc ...
- Nginx教程(三) Nginx日志管理 (转)
Nginx教程(三) Nginx日志管理 1 日志管理 1.1 Nginx日志描述 通过访问日志,你可以得到用户地域来源.跳转来源.使用终端.某个URL访问量等相关信息:通过错误日志,你可以得到系统某 ...
- PersistGate轻松几步让Redux实现数据持久化
在开发的过程中,数据用redux管理,觉得希望将数据持久化保存,也就是说当用户下一次打开app或网站的时候,我们希望浏览器/APP自动加载出上次的数据,怎么办?有没有一个
- 探索云数据库最佳实践 阿里云开发者大会数据库专场邀你一起Code up!
盛夏.魔都.科技 三者在一起有什么惊喜? 7月24日,阿里云峰会·上海——开发者大会将在上海世博中心盛大启程,与未来世界的开发者们分享数据库.云原生.开源大数据等领域的技术干货,共同探讨前沿科技趋势, ...
- Linux常用命令1 文件处理命令
1.命令格式 1.用中括号括起来的内容都不是必填内容,碧如上图的选项和参数,有些命令不写选项和参数也可以执行 2.注意图中的简化选项与完整选项说明,完整选项要两个横杆-- 2.目录处理命令ls 1.文 ...