Algorithms Dynamic Programming
Algorithms Dynamic Programming
It is technique mainly used to avoid the recursion. Because the recursion the
exponential time to get the result and we have to solve the things again even
though we have done already.
Dynamic programming is used when there is a overlapping of subproblems,
optimal substructure property.
Two types of approaches:
1) Memoization
2) Tabulation
Basically we store the results of these calculations and use whenever required.
Example:
Fibanocii sequence
Sum of Subsets Problem:
We have find whether there is a subset possible with the given target sum.
Using recursion: (Brute Force Approach)
SumofSubsets(array,n,target) = SumOfSubsets(array,n-1,target-arr[i]) or
SumOfSubsets(array,n-1,target)