Dynamic Programming

Definition

Dynamic programming represents recurring subproblems as states and defines which smaller states determine the current one. Solve base cases first and follow the dependencies, or save results during recursion to avoid repeated work.

Core rule: Define the objective, state fields and base cases. List choices and transitions, then test on a small example to see whether the state omits anything that matters later.

Say you're planning three hours of afternoon talks. Twenty proposals come in, each with a length and a count of audience votes. You want the talks that fit the time and add up to the most votes.

Try making a few schedules on paper and you see the trouble. Each talk can go in or stay out, so there are over a million combinations. How many of those do you want to check by hand?

Dynamic programming solves a smaller problem once and keeps the answer for each time it comes up again. Let's take it through that afternoon schedule, then see what happens when the table leaves something important out.

How it works

In the nineteen fifties, American mathematician Richard Bellman developed the idea behind the table. If a route is best all the way through, the rest of it should also be best from the point you've reached.

Think of reaching a crossroads and asking how far it is to the station. The answer is ten minutes whether you came from the east or west. Once you're there, you can work out the best way to finish from where you stand.

  1. 01 · Define the states Specify the current step and remaining resources.
  2. 02 · List transitions Map each viable action to a smaller subproblem.
  3. +1 more mechanism steps & animation in the app

When it fails & limits

The trouble comes when two schedules seem to reach the same spot and actually don't. Leave out a restriction, and even a carefully filled table can give you the wrong schedule.

✦ Unlock full lesson in ConceptFlow

Unlock the full Dynamic Programming lesson in ConceptFlow

You’ve read the core idea and opening case. Get the ConceptFlow app to continue through the full breakdown, failure modes, 5-minute audio lesson, and decision practice.

  • ▸5-minute English & Mandarin audio lesson
  • ▸5 more deep-dive case & mechanism insights
  • ▸All 5 failure boundaries & counter-examples
  • ▸4-point decision checklist + 6-step practice

Tap a store button on mobile, or scan with your phone camera on desktop.