ITA 15.5 Optimal binary search trees
2016-08-27 13:11
141 查看
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)
相关文章推荐
- optimal_binary_search_tree introduction to algorithm 3rd, example 15.5
- 【Leetcod】Unique Binary Search Trees II
- LeetCode OJ :Unique Binary Search Trees II(唯一二叉搜索树)
- leetcode 096 Unique Binary Search Trees
- LeetCode —— Unique Binary Search Trees [动态规划]
- 95. Unique Binary Search Trees II
- Unique Binary Search Trees
- 96. Unique Binary Search Trees
- 95. Unique Binary Search Trees II -Meidum
- Unique Binary Search Trees II
- Unique Binary Search Trees II
- [96]Unique Binary Search Trees
- Unique Binary Search Trees
- LeetCode-Unique Binary Search Trees
- unique binary search trees
- unique-binary-search-trees-ii
- 95. Unique Binary Search Trees II
- (leetcode )Unique Binary Search Trees
- Unique Binary Search Trees
- leetcode-Unique Binary Search Trees II