Memoization

  1. Make it work
    1. visualize the problem as a tree
    2. implement the tree using recursion
    3. test it
  2. Make it efficient
    1. add a memo object (typically a dictionary)
    2. add a new base case to return memo values
      1. se ho il valore memorizzato nel memo obj, allora usa quello
      2. altrimenti memorizzalo nell’oggetto memo

Memoization recipe

Approach to solve problems (top-down).

Make it work

  • visualize the problem as a tree
  • implement the tree using recursion
  • test it

Make it efficient

  • add memo object
  • add a base case to return memo values
  • store return values into the memo