简体   繁体   English

动态编程-最佳断点

[英]dynamic programming - optimal break point

I learned that using dynamic programming, the matrix chain multiplication problem can be solved in n^3 time, while for the optimal binary tree problem, we also get n^3 time, but then we could optimize it to n^2. 我了解到,使用动态规划,矩阵链乘法问题可以在n ^ 3的时间内解决,而对于最佳二叉树问题,我们也可以得到n ^ 3的时间,但是可以将其优化为n ^ 2。 Why is this? 为什么是这样? I got a statement saying that this is because in the matrix multiplication problem, the optimal break point of the chain M(i,n) could be larger than the optimal break point of the chain M(i+1,n). 我得到一条说法,这是因为在矩阵乘法问题中,链M(i,n)的最佳断点可能大于链M(i + 1,n)的最佳断点。 Can someone help me understand this? 有人可以帮我理解吗? Why is this true in the matrix multiplication problem, but not in the optimal binary tree problem? 为什么在矩阵乘法问题中而不是在最佳二叉树问题中如此?

Thanks 谢谢

Given an interval of keys I1 that is a sub-interval of I2, the query cost of the optimal binary tree on I1 is no greater than the query cost of the optimal binary tree on I2 (this should be fairly intuitive, but formally, take the optimal tree for I2 and repeatedly delete keys from it via the standard algorithm). 给定键间隔I1作为I2的子间隔,则I1上的最佳二叉树的查询成本不大于I2上的最佳二叉树的查询成本(这应该是很直观的,但从形式上讲, I2的最佳树,并通过标准算法反复从中删除密钥)。 This means that you can think of the process of finding the optimal break point as a sort of balancing process between the two halves. 这意味着您可以将找到最佳断点的过程看作是两半之间的一种平衡过程。

This is not true for matrix chain: the cost of multiplying (100, 100), (100, 100) is much greater than (100, 100), (100, 100), (100, 1), because two matrix-vector multiplications is much cheaper than a matrix-matrix. 对于矩阵链而言并非如此:乘以(100,100),(100,100)的成本远大于(100,100),(100,100),(100,1),因为两个矩阵向量乘法比矩阵间便宜得多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM