记忆和动态规划的区别是什么?我认为动态规划是记忆的一个子集。对吗?
当前回答
编程相关文章。指南:动态规划vs记忆vs制表
记忆和动态规划的区别是什么?
记忆是描述一种优化技术的术语,在这种技术中缓存以前计算的结果,并在再次需要相同的计算时返回缓存的结果。
动态规划是一种迭代求解递归性质问题的技术,适用于子问题的计算重叠的情况。
动态编程通常使用制表实现,但也可以使用记忆实现。所以你可以看到,两者都不是另一个的“子集”。
一个合理的后续问题是:制表(典型的动态编程技术)和记忆之间的区别是什么?
当你用制表法解决一个动态规划问题时,你是“自底向上”地解决问题,也就是说,首先解决所有相关的子问题,通常是填满一个n维表。根据表中的结果,然后计算“顶部”/原始问题的解决方案。
如果您使用记忆来解决问题,您可以通过维护已经解决的子问题的映射来实现。从“自顶向下”的意义上说,首先解决“顶部”问题(通常递归向下解决子问题)。
这里有一个很好的幻灯片(链接现在死了,但幻灯片仍然很好):
If all subproblems must be solved at least once, a bottom-up dynamic-programming algorithm usually outperforms a top-down memoized algorithm by a constant factor No overhead for recursion and less overhead for maintaining table There are some problems for which the regular pattern of table accesses in the dynamic-programming algorithm can be exploited to reduce the time or space requirements even further If some subproblems in the subproblem space need not be solved at all, the memoized solution has the advantage of solving only those subproblems that are definitely required
额外的资源:
维基百科:记忆,动态规划 相关SO Q/A:动态规划的记忆或制表方法
其他回答
从维基百科:
记忆有关
在计算中,记忆是一种主要使用的优化技术 通过函数调用来加速计算机程序,避免重复 对先前处理过的输入的结果的计算。
动态规划
在数学和计算机科学中,动态规划是一种方法 把复杂的问题分解成更简单的问题 子问题。
当把一个问题分解成更小/更简单的子问题时,我们经常会不止一次遇到相同的子问题——所以我们使用Memoization来保存以前的计算结果,这样我们就不需要重复它们了。
动态编程经常遇到使用内存是有意义的情况,但您可以使用任何一种技术而不必使用另一种技术。
动态规划是一种求解给定问题的算法范式 将复杂问题分解为子问题并存储结果 以避免再次计算相同的结果。
http://www.geeksforgeeks.org/dynamic-programming-set-1/
记忆是一种跟踪以前解决的解决方案的简单方法(通常实现为哈希键值对,而不是通常基于数组的制表),这样当它们再次遇到时就不会重新计算。它可以在自底向上或自顶向下的方法中使用。
请参阅关于记忆和制表的讨论。
动态规划是一种通过求解递归关系/递归并通过制表或记忆存储先前找到的解来解决某些类型问题的方法。记忆是一种跟踪以前解决问题的解决方案的方法,可以与任何对于给定输入集具有唯一确定性解决方案的函数一起使用。
编程相关文章。指南:动态规划vs记忆vs制表
记忆和动态规划的区别是什么?
记忆是描述一种优化技术的术语,在这种技术中缓存以前计算的结果,并在再次需要相同的计算时返回缓存的结果。
动态规划是一种迭代求解递归性质问题的技术,适用于子问题的计算重叠的情况。
动态编程通常使用制表实现,但也可以使用记忆实现。所以你可以看到,两者都不是另一个的“子集”。
一个合理的后续问题是:制表(典型的动态编程技术)和记忆之间的区别是什么?
当你用制表法解决一个动态规划问题时,你是“自底向上”地解决问题,也就是说,首先解决所有相关的子问题,通常是填满一个n维表。根据表中的结果,然后计算“顶部”/原始问题的解决方案。
如果您使用记忆来解决问题,您可以通过维护已经解决的子问题的映射来实现。从“自顶向下”的意义上说,首先解决“顶部”问题(通常递归向下解决子问题)。
这里有一个很好的幻灯片(链接现在死了,但幻灯片仍然很好):
If all subproblems must be solved at least once, a bottom-up dynamic-programming algorithm usually outperforms a top-down memoized algorithm by a constant factor No overhead for recursion and less overhead for maintaining table There are some problems for which the regular pattern of table accesses in the dynamic-programming algorithm can be exploited to reduce the time or space requirements even further If some subproblems in the subproblem space need not be solved at all, the memoized solution has the advantage of solving only those subproblems that are definitely required
额外的资源:
维基百科:记忆,动态规划 相关SO Q/A:动态规划的记忆或制表方法
动态规划通常被称为记忆!
Memoization is the top-down technique(start solving the given problem by breaking it down) and dynamic programming is a bottom-up technique(start solving from the trivial sub-problem, up towards the given problem) DP finds the solution by starting from the base case(s) and works its way upwards. DP solves all the sub-problems, because it does it bottom-up Unlike Memoization, which solves only the needed sub-problems DP has the potential to transform exponential-time brute-force solutions into polynomial-time algorithms. DP may be much more efficient because its iterative On the contrary, Memoization must pay for the (often significant) overhead due to recursion.
简单来说, 记忆法使用自顶向下的方法来解决问题,即从核心(主要)问题开始,然后将其分解为子问题,并以类似的方式解决这些子问题。在这种方法中,同一子问题可能会多次出现,消耗更多的CPU周期,从而增加时间复杂度。而在动态规划中,同一子问题不会求解多次,而是利用其先验结果来优化解。
在动态规划中,
没有递归的开销,维护表的开销也更少。 表访问的规则模式可用于减少时间或空间需求。
在记忆中,
有些子问题不需要解决。