动态编程记忆化或制表方法记忆、方法、动态

2023-09-11 03:12:37 作者:玖辞.

有可以使用动态编程如不少问题需要解决最长递增子。这个问题可以通过使用2的办法来解决

There are many problems that can be solved using Dynamic programming e.g. Longest increasing subsequence. This problem can be solved by using 2 approaches

在记忆化(自上而下) - 使用递归解决子问题,并把结果存储在一些哈希表 制表(自下而上) - 使用迭代方法通过首先解决较小的子问题,然后的更大的问题的执行过程中使用它来解决问题

我的问题是,这是在时间和空间的复杂性方面更好的办法?

My question is which is better approach in terms of time and space complexity?

推荐答案

简短的回答:!这取决于问题

记忆化的通常需要更多的code,是那么直接,但计算的优势,在一些问题,主要是那些你做的没有的需要计算所有的值为全矩阵到达应答

Memoization usually requires more code and is less straightforward, but has computational advantages in some problems, mainly those which you do not need to compute all the values for the whole matrix to reach the answer.

制表的是更简单,但可能不必要的计算值。如果你需要计算所有的值,这种方法通常更快,因为较小的开销,不过,

Tabulation is more straightforward, but may compute unnecessary values. If you do need to compute all the values, this method is usually faster, though, because of the smaller overhead.