Dynamic Programming21 sections · 916 units
Open in Course

Common Mistakes

What to avoid

1.1. Forgetting to prove QI: Don't assume it holds. Prove it for your cost function.

2.2. Wrong iteration order (Knuth): Process by length, not by ii then jj.

3.3. Off-by-one errors: Bounds are [opt[i][j1],opt[i+1][j]][opt[i][j-1], opt[i+1][j]]. Check edge cases.

4.4. Not storing opt: You need optopt values to bound future searches. These optimizations are tricky. Test on small inputs first.