Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Dynamic Programming Thinking Lab
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
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
1.0x