Module 10 · Dynamic Programming · Common Mistakes

Dynamic Programming: common mistakes

Memoization is a table and two lines of code; leave one out, or put the base cases in the wrong order, and you get the wrong answer or the exponential tree back. Both slips here are in Subset Sum: a box is a call (currIndex, remSum) and shows what it returns; a pink box was solved before.

Pick a mistake and press play: Wrong runs the code with the mistake until it breaks, and the code marks the wrong line in red. Fixed runs the corrected code on the same input, with the corrected line in green.

Mistake
Code