Lecture 14: Practice Problems

1. Unbounded Knapsack

What if you can take multiple copies of each item?

Show Answer

Recurrence Change:

Instead of Max(DP[i-1][w], v + DP[i-1][w-wi]),

Use Max(DP[i-1][w], v + DP[i][w-wi]).

Basically, after taking item i, we are still allowed to take item i again (stay in row i).

2. Bellman-Ford Optimization

Can we stop early in Bellman-Ford?

Show Answer

Yes.

If an iteration results in NO relaxations (no distance changes), we can terminate immediately. The distances have converged.