Can Sum with Tabulation
Updated: 01 February 2024
Problem
The same problem as the Memoization Can Sum problem but we want to take a tabular approach
When using a table we should consider a table size based on the target number we want for this problem, in this context we will use the array size as target+1
. For initialization we consider the resulting type, in this case we want a boolean so we initialize the entire array to false
In this case we also consider that the sum of 0 is always true, so we set this in the table. Our initial setup of our table then represents:
Now we will iterate through each section checking if any given value is possible using any ofthe other numbers we have by setting that sum as true. Furthermore, we can only evaluate if a sum is possible by updating data based on a sum that is already possible
The overall idea of how we transition state can be seen below:
Tabulation Implementation
The implementation of this can be seen below:
In the above, the time complexity and space complexity