diff --git a/src/js/algorithms/dynamic-programing/knapsack.js b/src/js/algorithms/dynamic-programing/knapsack.js index 9c979360..d72e819d 100644 --- a/src/js/algorithms/dynamic-programing/knapsack.js +++ b/src/js/algorithms/dynamic-programing/knapsack.js @@ -1,4 +1,4 @@ -function findValues(n, capacity, kS) { +function findValues(n, capacity, kS, weights, values) { let i = n; let k = capacity; // console.log('Items that are part of the solution:'); @@ -7,8 +7,8 @@ function findValues(n, capacity, kS) { // console.log( // item ' + i + ' can be part of solution w,v: ' + weights[i - 1] + ',' + values[i - 1] // ); + k -= weights[i-1] i--; - k -= kS[i][k]; } else { i--; } diff --git a/src/js/algorithms/dynamic-programing/matrix-chain-multiplication.js b/src/js/algorithms/dynamic-programing/matrix-chain-multiplication.js index 143f5772..87a736b6 100644 --- a/src/js/algorithms/dynamic-programing/matrix-chain-multiplication.js +++ b/src/js/algorithms/dynamic-programing/matrix-chain-multiplication.js @@ -25,7 +25,7 @@ export function matrixChainOrder(p) { } } for (let l = 2; l < n; l++) { - for (let i = 1; i <= (n - l) + 1; i++) { + for (let i = 1; i <= n - l; i++) { const j = (i + l) - 1; m[i][j] = Number.MAX_SAFE_INTEGER; for (let k = i; k <= j - 1; k++) {