Let,
Let the subproblem be So at each subproblem, which is the sum can be made from remaining value of ‘ .
We have following condition:
This means for any value of ai, we can make sum up to ‘and it’s possible to obtainfrom n-1 integers also. Thus,is True.
This means ai cannot make value sum to ‘t’ and we can make value ‘t’ fromintegers. Thus,
is True.
- If above conditions are not true, then=False.
This shows that it is not possible to make sum value ‘ from using some integers.
So, the recursive equation is:
Where In dynamic programming have to compute only distinct function call because as soon as compute and store in one data structure so that after this reuse afterward if it is needed. And it is always solved in time by using dynamic programming paradigm. Here we will first define the recurrence relation and then solve each subproblem recursively.
Analysis of Above Recursive Relation in which each subproblem can be computed in time that is, in linear time. After computing Thus, the runtime is