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 ...
随机推荐
- 洛谷P1082 同余方程 [2012NOIP提高组D2T1] [2017年6月计划 数论06]
P1082 同余方程 题目描述 求关于 x 的同余方程 ax ≡ 1 (mod b)的最小正整数解. 输入输出格式 输入格式: 输入只有一行,包含两个正整数 a, b,用一个空格隔开. 输出格式: 输 ...
- hdu 1671&& poj 3630 (trie 树应用)
Phone List Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 25280 Accepted: 7678 Descr ...
- LintCode刷题笔记-- Edit distance
标签:动态规划 描述: Given two words word1 and word2, find the minimum number of steps required to convert wo ...
- freemarker自定义标签(与java合用)
自定义类继承FreemarkerManager类,重写protected Configuration createConfiguration(ServletContext servletContext ...
- C++中数字转换成字符串
头文件:<string> 转换函数:to_string(); 例如:int n=10; string str=to_string(n) ;
- Linux安装mongoDB步骤和方法
Linux安装mongoDB步骤和方法 下载mongoDB数据库 mongodb-linux-x86_64-3.0.15.tgz 存放到linux文件夹中 ftp软件直接拖上去 解压文件夹(解压后,会 ...
- Linux上编辑然后执行一段脚本的机制
简要分析下刚开始提出的第二个问题, 因为没看代码,所以只是简单流程 1. 在bash里打开vim编辑文件并保存退出: bash进程fork子进程, 然后调用exec装入vim程序,wait这个子进程v ...
- WPF自定义控件 依赖属性绑定
控件cs文件 using System.ComponentModel; using System.Windows; using System.Windows.Controls; using Syste ...
- 【Leetcode链表】移除链表元素(203)
题目 删除链表中等于给定值 val 的所有节点. 示例: 输入: 1->2->6->3->4->5->6, val = 6 输出: 1->2->3-&g ...
- oracle获取中文出现乱码问题解决
首先搞清楚字符集和字符编码概念,了解oracle字符集原理,请参考一位大神的讲解: ref:http://blog.csdn.net/dbanote/article/details/9158367#c ...