educative.io

Educative

Visualization of knapsack top down approach with memoization

Hi, It is very difficult to understand the memoization (top down approach). Can someone explain the following questions
why do we select two dimensional array to store the results of sub problems.?
how to visualize the values populated to the array?
Thanks,
sat

Hi Satj ,
Hope you are doing good.
We have used a two-dimensional array here to store values because we have two variables over here i.e. capacity and current index.
Regarding the visualization part, the illustrations in the lesson show the method of populating the two-dimensional array made.
Hope this helps.