Skip to main content

Posts

Showing posts from July, 2020

Subset Sum In Dynamic Programming

Subset Sum using Dynamic Programming DP Tutorial 3 Prerequisite – Tutorial 1 , Tutorial 2 Problem Statement- Given a array of integer you have to tell if there is subset present in array which have the sum equal to given array. Eg.arr[]=[2,3,7,8,10]      Sum=11 Output -Yes Sumset={3,8} Parent Problem - 0-1    knapsack how it is related to 0-1 knapsack? I want to tell again that we try to drive solution of child problem from parent problem.In this problem we can choose a element or not and any where if this type of pattern trigger then surely that problem can be solved using 0-1 knapsack pattern.And as we forward in tutorial you can easily find. Choice diagram of subset sum Choice diagram of 0-1 knapsack How to identify Dynamic Programming - 1.choice – In this problem you can choose a element or not.Condition 1 is satisfied. 2.Optimal- In this problem you can’t see the maximum or minimum don’t worry now assign 1 to yes a...

0-1 knapsack Bottom Up Dynamic Programming

0-1      knapsack Using Bottom Up Dynamic Programming- Dp Tutorial -2 prerequisite https://spoj-editorial1.blogspot.com/2020/07/0-1-knapsack-in-dynamic-programming.html problem Statement- you are given a weight array and respective value array and maximum size of knapsack and you have to put these item in such a way so that you will get maximum total value in knapsack. Type of solution- Recursive=base condition+recursive call Memorization=recursive call +table Bottom up=table   Why we use Bottom Up dynamic programming? In recursive solution there may cause a problem of stack overflow so avoid this problem we use bottom up technique. How to solve- In this dynamic programming tutorial we only focus to drive solution from previously tutorial. now we have to convert recursive +   memoization =>bottom Up lets understand table- eg. Weight[]=[1,3,4,5] Value=[1,4,5,7] W=7 in left side from row 0 to 4- row 0 means you have empty ...