Problem Solving

Concept shape

Practice pattern
0
1
2
3
4
5
Definition

Dynamic programming solves overlapping subproblems once and reuses the answers.

Step 1 / 5
Concept shape
Current lesson

Dynamic Programming Thinking Lab

Problem Solving Practice pattern

Dynamic Programming Thinking

Welcome to the Dynamic Programming Thinking concept lab. Dynamic programming is useful when the same smaller questions appear again and again. Instead of recomputing those answers, you store them in a memo table or build them bottom-up in an array. The hard part is not writing the table. The hard part is naming the state clearly enough that each answer depends only on smaller known answers. The must know points are: Define state clearly. Find transition between states. Choose top-down memoization or bottom-up tabulation. The common operations are: state, transition, base case, memoize. The complexity shape is Number of states times transition cost. Watch out for these pitfalls: Unclear state definition. Wrong base cases. Computing states in the wrong order. Related algorithms include Memoized Fibonacci, 0/1 Knapsack, Coin Change.

Concept details

Dynamic programming is useful when the same smaller questions appear again and again.

Instead of recomputing those answers, you store them in a memo table or build them bottom-up in an array.

The hard part is not writing the table. The hard part is naming the state clearly enough that each answer depends only on smaller known answers.

Must know

  • Define state clearly.
  • Find transition between states.
  • Choose top-down memoization or bottom-up tabulation.

Complexity

Number of states times transition cost

Open deeper visual structure lesson
1.0x