CS Wiki | Cedric Schwyter

Dynamic Programming

Dynamic Programming

Motivation

DP can be used to easily reduce recursive problems from exponential runtime to down polynomial and oftentimes even linear runtime by using tabulation (bottom-up) and memoization (top-down). It makes use of the overlapping subproblems structure and optimal substructure properties of certain problems.

General Roadmap for DP Problems

  1. Definition of the DP table:
    1. What dimensions does the table have?
    2. What is the meaning of each entry?
  2. Computation of an entry:
    1. How can an entry be computed from the values of other entries?
    2. Specify the base cases, i.e., the entries that do not depend on others.
  3. Calculation order:
    1. In which order can entries be computed so that values needed for each entry have been determined in previous steps?
  4. Extracting the solution: How can the final solution be extracted once the table has been filled?
  5. Running time:
    1. What is the running time of your solution?

Subset Sum Problem

We have a set of elements that need to be split into two sets such that the sum of those sets is equal. Let be that sum.

Idea: is subset sum of or is subset sum of . Let be a predicate defined by .

Recurrence:

computes a new entry.

gives the solution.

Knapsack Problem

We have a set of elements. Every element has a value and a weight . We have a maximum weight limit . We are looking to maximize the summed value of the elements such that the sum of their weights is smaller than . Let be a function such that gives the maximum achievable value from values such that their weights summed up remain smaller than .

Recurrence:

computes an entry.

gives the solution.

This project is maintained by D3PSI