Memoization or Tabulation approach for Dynamic programming

Mady picture Mady · Aug 20, 2012 · Viewed 10k times · Source

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. Memoization (Top Down) - Using recursion to solve the sub-problem and storing the result in some hash table.
  2. Tabulation (Bottom Up) - Using Iterative approach to solve the problem by solving the smaller sub-problems first and then using it during the execution of bigger problem.

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

Answer

behnam picture behnam · Aug 20, 2012

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.