Ctrl/Cmd + P and select "Save as PDF".
Knapsack(v, w, n, W)
let K[0..n][0..W] be a new table
for i = 0 to n
for current_w = 0 to W
if i == 0 or current_w == 0
K[i][current_w] = 0 // Base case
else if w[i] <= current_w
K[i][current_w] = max(K[i-1][current_w],
v[i] + K[i-1][current_w - w[i]])
else
K[i][current_w] = K[i-1][current_w]
return K[n][W]Knapsack-1D(v, w, n, W)
let DP[0..W] be array initialized to 0
for i = 1 to n
for current_w = W down to w[i]
DP[current_w] = max(DP[current_w],
v[i] + DP[current_w - w[i]])
return DP[W]LCS-Length(X, Y)
m = length(X), n = length(Y)
let C[0..m][0..n] be a new table
for i = 0 to m: C[i][0] = 0
for j = 0 to n: C[0][j] = 0
for i = 1 to m
for j = 1 to n
if X[i] == Y[j]
C[i][j] = C[i-1][j-1] + 1
else
C[i][j] = max(C[i-1][j], C[i][j-1])
return C[m][n]