Subset Sum—Dynamic Programming
Understand how to apply dynamic programming to solve the subset sum problem. Learn to implement a memoized algorithm in Python that determines if a subset of numbers sums to a target efficiently. This lesson improves problem-solving skills by exploring optimization over recursive solutions.
We'll cover the following...
We'll cover the following...
Dynamic programming algorithm for subset sum problem
Recall that the subset sum problem asks whether any subset of a given array of positive integers sums to a given integer . In a previous lesson, we developed a recursive subset sum algorithm that can be reformulated as follows. Fix the original input array and define the boolean function if and only if some subset of sums to
We need to compute . This function satisfies the following recurrence:
...