Week 9 - Dynamic Programming Flashcards

1
Q

What is dynamic programming

A

Dynamic programming is a method for solving complex problems by breaking them down into simpler overlapping subproblems, solving each subproblem once, and storing their solutions to avoid redundant computations.

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

How does dynamic programming work, step by step?

A

Here’s how dynamic programming works, explained step by step:

  1. Initialize a Grid: Start with an empty grid where rows represent items and columns represent sub-wallet sizes.
  2. Fill the First Row: For each cell in the first row, determine if the first item fits into the sub-wallet. If it fits, place the item’s value in that cell.
  3. Move to the Next Row: For each subsequent item (row), check if it fits into each sub-wallet size (column). If it doesn’t fit, retain the previous value. If it fits, compare the value of including the item with the current best and update the cell accordingly.
  4. Combine Values: When an item fits and leaves extra space, add the best value from the remaining space to maximize the total value.
  5. Repeat Until Complete: Continue this process until all items and sub-wallet sizes are considered, filling in the grid to reflect the best possible value at each step.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does dynamic programming solve the knapsack problem?

A

Dynamic programming solves the knapsack problem by starting with smaller “sub-knapsacks” and progressively building up to the original problem. It uses a grid where rows represent items and columns represent knapsack sizes, filling in the grid with sub-knapsack values step by step. By solving these smaller sub-problems first, the algorithm efficiently calculates the optimal value for the full knapsack.

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

Can you add more items to the knapsack after solving the problem?

A

Yes! But new maximum values need to be calculated. Dynamic programming will continue to build on the existing grid to update the solution.

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

Can you change the order of the rows in the dynamic programming grid?

A

Yes! Changing the order of the rows has no effect on the outcome, as the row order doesn’t matter.

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

Can you fill the grid column-wise instead of row-wise in dynamic programming?

A

For this problem, it works, but it may not be effective for others.

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

Can you add an item with a smaller size to the knapsack?

A

Yes! However, you would likely need to recompute the entire grid to account for the new item.

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

Does dynamic programming handle splitting items (and their values)?

A

No! Dynamic programming only works for whole items. But a greedy algorithm would work!

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

Can dynamic programming handle items that depend on each other?

A

No, dynamic programming only works when each subproblem is discrete and does not depend on other subproblems.

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