1. Fractional Knapsack falls under Greedy ✅ and not under Dynamic programming
  2. Unbounded Knapsack → Unlimited supply of all items.
  3. Problem is broken down tobase_case andchoice_diagram
  4. To determinebase_case determine the smallest valid input.
    1. For knapsack if either the items is 0 or the weight is 0 then output will be 0. So this is the base case.
  5. In Recursion it always needs to be called with smaller input so recursion can exit else it will keep calling itself. To apply above in knapsack keep reducing size of array as iterating through the array, if the weight gets filled then exit.
  6. Two choice, when including the equation is going to reduce the weight in the recursive function so w - wt[n-1]
  7. The martix has to be created for variables that are changing. Here they are n + 1 and w + 1
  8. choice_diagram really made it easy to write above equation.
  9. Output should be sum of profits or maximum profit.
  10. To domemoization of above first identify where all recursive function is present,
  11. In the above three recursive function only two variables are changing, we will keep matrix of these two
  12. After thebase_case add the condition to check if value exists in the t matrix, if it exists then return it.
  13. Second change, before returning store the value in t matrix,
  14. In Recursion instead of initialising values with -1 can we keep them empty and check for undefined or null to see if value exists? This behaviour may be different language wise, it should be fine in Javascript.
  15. Matrix_Chain_Multiplication
  16. Recursion strong hoga toh Dynamic programming halwa lagegi.
  17. Bottom_Up or Tabulation approach the matrix size will be = bag weight * number of items.
  18. The first row and first column have to be initialised,
  19. base_case will turn into initialisation for the matrix, the initial row and column are going to be 0 becausebase_case tells that if weight is 0 or n is 0 then return 0. If it would have been -1 then we would have set -1.
  20. Code for initializing here
    let t = [];
    for (let i = 0; i < n + 1; i++) {
    	for (let j = 0; j < w + 1; j++) {
    		if (i == 0 || j == 0) {
    			t[i][j] = 0;
    		}
    	}
    }
  21. Recursive to tabulation
  22. Q. How will the recursive program change if the output should be the weight and value of all items instead of just the sum of weight/ value of the selected items.
  23. Identification of 6 problems for AV- Cat1. Knapsack, how to identify?