Memoization or Tabulation approach for Dynamic programming

前端 未结 3 1312
执笔经年
执笔经年 2020-12-24 02:30

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

  1. Memo
相关标签:
3条回答
  • 2020-12-24 02:58

    Asymptotically a dynamic programming implementation that is top down is the same as going bottom up, assuming you're using the same recurrence relation. However, bottom up is generally more efficient because of the overhead of recursion which is used in memoization.

    0 讨论(0)
  • 2020-12-24 03:04

    Short answer: it depends on the problem!

    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.

    0 讨论(0)
  • 2020-12-24 03:08

    If the problem has overlapping sub-problems property then use Memoization, else it depends on the problem

    0 讨论(0)
提交回复
热议问题