Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Image: ubuntu2004
The Sum Finder Problem
A array is created with multiplied by .
If there exists a subset of elements in from , whose sum is equal to the value of ;
.
Else, .
If the value in the row is , we can immediately evaluate the row to without any extraneous calculations, since we already know a subset of values equal to the value of exists.
Target value =
Set =
For the first row , we only have one value in our subset; .
So only the array element holding the value of will be appended to . The rest are .
For the second row, , we have two values in our subset; .
So the array element holding the values of will be appended to . The rest are .
Since we have already evaluated the elements in the position, we no longer need to evaluate the previous row and column numbers for values which have already been appended to but rather can continue to place a in all the remaining positions. We only need to evaluate the new additions to our subset.
For the third row, , we have three values in our subset; .
have already been evaluated. So, we only need to evaluate the addition of to the subset. The array elements holding the values of need to be appended to . The rest are .
For the fourth row, , we have four values in our subset; .
have already been evaluate. So, we only need to evaluate the addition of to the subset. The array elements holding the values of need to be appended to . The rest are .
Furthermore, we have already evaluated the element holding the value of to be , so the additional sum of to any of these values in our subset will append the values in the positions of the values to all be .
We already have our target value of . But for the sake of this exercise, lets evaluate the final row.
For the fifth row, , we have all five values in our subset; .
All other values in have been appended to with the exception of the values of . We have already evaluated the value of to be , so the addition of 6 will guarantee that some combination of the subset will equal a sum of , so we appended it to . The others remain .
Target value =
Set =
For the first row , we only have one value in our subset; .
So only the array element holding the value of will be appended to . The rest are .
For the second row, , we have two values in our subset; .
So the array element holding the values of will be appended to . The rest are .
For the third row, , we have three values in our subset; .
have already been evaluated. So, we only need to evaluate the addition of to the subset. The array elements holding the values of need to be appended to . The rest are .
For the fourth row, , we have four values in our subset; .
have already been evaluate. So, we only need to evaluate the addition of to the subset. The array elements holding the values of need to be appended to . The rest are .
Furthermore, we have already evaluated the element holding the value of to be , so the additional sum of to any of these values in our subset will append the values in the positions of the values to all be .
For the fifth row, , we have all five values in our subset; .
All other values in have been appended to with the exception of the values of . We have already evaluated the value of to be , so the addition of will guarantee that some combination of the subset will equal a sum of so we appended them to . The others remain .