LN4 Dynamic programming problems: Flashcards
Subset Sum, Knapsack, Sequence Alignment
What is the subset sum problem?
Given a set of integers and a target sum
𝑊
W, the subset sum problem seeks a subset of integers that sum exactly to
𝑊
W or confirms no such subset exists.
How does DP solve the subset sum problem?
DP uses a Boolean function P(j, w), where P(j, w) = 1 if a subset of the first j items sums to w; otherwise, P(j, w) = 0.
What is the recurrence relation for the subset sum problem in DP?
P(j, w) = P(j - 1, w) or P(j - 1, w - w_j) if w >= w_j; otherwise, P(j, w) = P(j - 1, w).
What is the 0/1 knapsack problem?
The knapsack problem is a DP problem where we aim to maximize value in a knapsack of limited capacity, choosing from a set of items each with a weight and value.
How is the knapsack problem solved using DP?
Define OPT(j, w) as the maximum value from the first j items that doesn’t exceed capacity w, with OPT(j, w) = max(OPT(j - 1, w), OPT(j - 1, w - w_j) + v_j) when w >= w_j.
What is the base condition for the 0/1 knapsack DP function?
OPT(0, w) = 0 for all w, representing that with zero items, no value can be obtained.
What modification allows solving the knapsack problem where multiple copies of each item are allowed?
Change the recurrence to OPT(j, w) = max(OPT(j - 1, w), OPT(j, w - w_j) + v_j) for allowing repeated items.
Why does the modified formula work for unlimited copies in the knapsack problem?
OPT(j, w) now considers using the current item multiple times by including it in the same recursive step, making repeated inclusion possible.
How does the generalized subset sum differ from the exact subset sum problem?
If no subset exactly sums to W, the generalized subset sum problem finds the subset with the largest possible sum below W.
What is the recurrence relation for the generalized subset sum problem?
OPT(j, w) = max(OPT(j - 1, w), OPT(j - 1, w - w_j) + w_j), ensuring we get the maximum possible sum not exceeding w.
What is a segmentation problem in DP?
It is a problem where a sequence is divided into segments to maximize or minimize the total score based on a function evaluating each segment.
What is the DP recurrence for segmentation?
OPT(j) = min{OPT(i - 1) + e_{ij}}, where e_{ij} is the penalty of the segment (x_i, …, x_j).
What is the sequence comparison problem?
It involves transforming one string into another with the minimum number of edit operations, such as insertions, deletions, or substitutions.
How does DP solve the sequence comparison problem?
DP defines an alignment cost and recursively calculates the minimum edits by matching, inserting, or deleting characters as needed.
Why is the sequence comparison important in fields like bioinformatics?
It is used to align and compare DNA or protein sequences, estimate evolutionary distances, and detect mutations or variations.