简体   繁体   English

就时间复杂度而言,自下而上的 DP 解决方案是否优于自上而下?

[英]Is Bottom-up DP solution better than Top-down in terms of Time complexity?

Are there any Dynamic Programming Problems where the Bottom-Up solution has better time complexity than Top-Down (Memoization) solution?是否存在自下而上解决方案比自上而下(记忆化)解决方案具有更好时间复杂度的动态规划问题?

You might be able to make one up, but generally no.你也许可以弥补一个,但通常不会。

When both kinds of solutions are available, the worst case time complexities are the same.当两种解决方案都可用时,最坏情况的时间复杂度是相同的。

Bottom-up solutions are often faster in the worst case, in absolute terms (not asymptotic complexity) because memoization is a relatively expensive operation.在最坏的情况下,自下而上的解决方案通常更快,绝对值(不是渐近复杂度),因为记忆是一项相对昂贵的操作。

Top-down solutions are often faster in best or special cases, because they evaluate only the subproblems that are needed for each problem instance.在最佳或特殊情况下,自上而下的解决方案通常更快,因为它们仅评估每个问题实例所需的子问题。

Asymptotically both DP and Memoization give the same Time Complexity. DP 和 Memoization 都渐近地给出相同的时间复杂度。 However, at run-time, the DP solution outpaces Memoization technique by some constant factor.然而,在运行时,DP 解决方案以某个恒定因素超过了记忆技术。
This is because of the fact that in the case of DP we just need to look into the table for results of sub-problems while in case of Memoization we need to call recursion and then it returns the result whether by directly checking into hashtable/array(whatever you used) if its already computed or by computing it, which in turn consumes more CPU cycle.这是因为在 DP 的情况下,我们只需要在表中查看子问题的结果,而在 Memoization 的情况下,我们需要调用递归,然后它是否通过直接检查哈希表/数组来返回结果(无论你使用什么)如果它已经计算或通过计算它,这反过来又会消耗更多的 CPU 周期。

In some cases, it might happen that our sub-problem space is very large but we do not require all sub-problems to get our answer then, Memoization could be lucrative because it solves only inevitable problems instead of all.在某些情况下,我们的子问题空间可能非常大,但我们并不需要所有子问题来得到我们的答案,记忆化可能是有利可图的,因为它只解决了不可避免的问题而不是全部。 But, this case is very seldom to occur because Many a time we optimise our DP code only in such a way that it doesn't iterate for all sub-problems instead only for required sub-problems.但是,这种情况很少发生,因为很多时候我们只优化我们的 DP 代码,它不会对所有子问题进行迭代,而是只对所需的子问题进行迭代。

Hence, generally speaking, Bottom-Up approach ie, DP solution always runs faster than its corresponding Memoization solution.因此,一般来说,Bottom-Up 方法,即 DP 解决方案总是比其相应的 Memoization 解决方案运行得更快。

Note: I'm using the word runs faster instead of time complexity because time complexity is asymptotic which is same for both.注意:我使用的是运行速度更快这个词而不是时间复杂度,因为时间复杂度是渐近的,两者都是相同的。

暂无
暂无

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

相关问题 从上到下到自下而上的算法(DP) - Going from a top-down to a bottom-up algorithm (DP) Mergesort - 自上而下快于自上而下吗? - Mergesort - Is Bottom-Up faster than Top-Down? 何时使用自下而上 DP 何时使用自上而下 DP - when to use bottom-up DP and when to use top-down DP 如果记忆是自上而下的深度优先,而 DP 是自下而上的广度优先,那么自上而下的广度优先/自下而上的深度优先等价物是什么? - If memoization is top-down depth-first, and DP is bottom-up breadth-first, what are the top-down breadth-first / bottom-up depth-first equivalents? 这种算法是哪种递归解析?自下而上还是自上而下? - Which kind of recursive parsing is this algorithm? Bottom-up or top-down? 后序遍历==自下而上遍历和前序遍历==自上而下遍历? - Is post-order traversal == bottom-up traversal and pre-order traversal == top-down traversal? 动态规划:在 ProjectEuler 上的问题 31 上将自下而上的方法转换为自上而下的方法 - Dynamic Programming: Convert bottom-up approach to top-down on Problem 31 on ProjectEuler 使用自上而下或自下而上的方法构建 maxHeap/minHeap 时,两种方法的数组中的值是否会略有不同? - when building maxHeap/minHeap using top-down or bottom-up approach ,will the values in the array be slightly different for both the approaches? 自上而下DP的自下而上DP - Bottom Up DP from Top Down DP 自下而上法(DP)中斐波那契数列的时间复杂度 - Time Complexity of fibonacci series in Bottom Up approach(DP)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM