All lessons in Software Engineering: Programs, Systems, and Maintainable Software

Dynamic Programming from a Recurrence

Specify state, transitions, base cases, and reconstruction for a small optimization problem.

45 minutes · Members lesson · preview

What you will learn

  • Define a subproblem state and derive its recurrence from the final decision.
  • Distinguish an unreachable state from a valid zero-cost result.
  • Reconstruct an optimal solution and account for time and space costs.

A supplier offers reusable shipping containers holding 1, 3, or 4 books. You need containers for exactly six books with the smallest number of containers. Repeatedly choosing the largest capacity gives 4, 1, 1, but 3, 3 uses fewer. A plausible greedy choice has no proof that it preserves the optimum.

Dynamic programming reuses solutions to overlapping subproblems. It begins with a precise state and recurrence, not with a memorization table chosen by habit. The shipping problem is a teaching model with unlimited containers of each size and an exact-fill requirement.

Choose another lesson