LN4 Dynamic programming problems: Flashcards

Subset Sum, Knapsack, Sequence Alignment

1
Q

What is the subset sum problem?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does DP solve the subset sum problem?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the recurrence relation for the subset sum problem in DP?

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the 0/1 knapsack problem?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How is the knapsack problem solved using DP?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the base condition for the 0/1 knapsack DP function?

A

OPT(0, w) = 0 for all w, representing that with zero items, no value can be obtained.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What modification allows solving the knapsack problem where multiple copies of each item are allowed?

A

Change the recurrence to OPT(j, w) = max(OPT(j - 1, w), OPT(j, w - w_j) + v_j) for allowing repeated items.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why does the modified formula work for unlimited copies in the knapsack problem?

A

OPT(j, w) now considers using the current item multiple times by including it in the same recursive step, making repeated inclusion possible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does the generalized subset sum differ from the exact subset sum problem?

A

If no subset exactly sums to W, the generalized subset sum problem finds the subset with the largest possible sum below W.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the recurrence relation for the generalized subset sum problem?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a segmentation problem in DP?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the DP recurrence for segmentation?

A

OPT(j) = min{OPT(i - 1) + e_{ij}}, where e_{ij} is the penalty of the segment (x_i, …, x_j).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the sequence comparison problem?

A

It involves transforming one string into another with the minimum number of edit operations, such as insertions, deletions, or substitutions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does DP solve the sequence comparison problem?

A

DP defines an alignment cost and recursively calculates the minimum edits by matching, inserting, or deleting characters as needed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why is the sequence comparison important in fields like bioinformatics?

A

It is used to align and compare DNA or protein sequences, estimate evolutionary distances, and detect mutations or variations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Give an example where a subset-sum could be applied in real life.

A

Subset sum can be used in finance to determine combinations of cash denominations to reach a specific amount without overpaying.

17
Q

How can dynamic programming help in approximate text matching?

A

DP can align keywords with text, allowing slight variations due to misspellings or grammatical differences for efficient information retrieval.

18
Q

What’s an example of a segmentation problem in data analysis?

A

Partitioning data sequences into nearly linear segments with minimal deviation helps in understanding trends and patterns in time-series analysis.