Skip to content

Commit f92455a

Browse files
committed
[Algorithm Design and Techniques]
1 parent 72d0a47 commit f92455a

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

src/ts/algorithms/dynamic-programing/knapsack.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ export function knapSack(capacity: number, weights: number[], values: number[],
1313
const a = values[i - 1] + kS[i - 1][w - weights[i - 1]];
1414
const b = kS[i - 1][w];
1515
kS[i][w] = a > b ? a : b; // max(a,b)
16-
console.log(a + ' can be part of the solution');
16+
// console.log(a + ' can be part of the solution');
1717
} else {
1818
kS[i][w] = kS[i - 1][w];
1919
}
2020
}
21-
console.log(kS[i].join());
21+
// console.log(kS[i].join());
2222
}
2323

2424
// extra algorithm to find the items that are part of the solution
@@ -37,13 +37,13 @@ function findValues(
3737
let i = n;
3838
let k = capacity;
3939

40-
console.log('Items that are part of the solution:');
40+
// console.log('Items that are part of the solution:');
4141

4242
while (i > 0 && k > 0) {
4343
if (kS[i][k] !== kS[i - 1][k]) {
44-
console.log(
44+
/* console.log(
4545
'item ' + i + ' can be part of solution w,v: ' + weights[i - 1] + ',' + values[i - 1]
46-
);
46+
); */
4747
i--;
4848
k = k - kS[i][k];
4949
} else {

src/ts/algorithms/dynamic-programing/longest-common-subsequence-print.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export function lcs(wordX: string, wordY: string) {
2727
solution[i][j] = l[i][j] === l[i - 1][j] ? 'top' : 'left';
2828
}
2929
}
30-
console.log(l[i].join());
31-
console.log(solution[i].join());
30+
// console.log(l[i].join());
31+
// console.log(solution[i].join());
3232
}
3333

3434
printSolution(solution, wordX, m, n);
@@ -55,5 +55,5 @@ function printSolution(solution: Array<Array<string>>, wordX: string, m: number,
5555
x = solution[a][b];
5656
}
5757

58-
console.log('lcs: ' + answer);
58+
// console.log('lcs: ' + answer);
5959
}

src/ts/algorithms/dynamic-programing/longest-common-subsequence.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function lcs(wordX: string, wordY: string) {
2222
l[i][j] = a > b ? a : b; // max(a,b)
2323
}
2424
}
25-
console.log(l[i].join());
25+
// console.log(l[i].join());
2626
}
2727

2828
return l[m][n];

src/ts/algorithms/dynamic-programing/matrix-chain-multiplication.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export function matrixChainOrder(p: number[]): number {
3232
}
3333
}
3434

35-
console.log(m);
36-
console.log(s);
35+
// console.log(m);
36+
// console.log(s);
3737

3838
printOptimalParenthesis(s, 1, n - 1);
3939

@@ -42,11 +42,11 @@ export function matrixChainOrder(p: number[]): number {
4242

4343
function printOptimalParenthesis(s: Array<Array<number>>, i: number, j: number) {
4444
if (i === j) {
45-
console.log('A[' + i + ']');
45+
// console.log('A[' + i + ']');
4646
} else {
47-
console.log('(');
47+
// console.log('(');
4848
printOptimalParenthesis(s, i, s[i][j]);
4949
printOptimalParenthesis(s, s[i][j] + 1, j);
50-
console.log(')');
50+
// console.log(')');
5151
}
5252
}

src/ts/algorithms/greedy/knapsack.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ function knapSack(capacity: number, weights: number[], values: number[]) {
77
if (weights[i] <= capacity - load) {
88
val += values[i];
99
load += weights[i];
10-
console.log('using item ' + (i + 1) + ' for the solution');
10+
// console.log('using item ' + (i + 1) + ' for the solution');
1111
} else {
1212
const r = (capacity - load) / weights[i];
1313
val += r * values[i];
1414
load += weights[i];
15-
console.log('using ratio of ' + r + ' for item ' + (i + 1) + ' for the solution');
15+
// console.log('using ratio of ' + r + ' for item ' + (i + 1) + ' for the solution');
1616
}
1717
}
1818
return val;

0 commit comments

Comments
 (0)