Dynamic Programming
Learn to spot overlapping subproblems, solve them top-down with memoization or bottom-up with a table, squeeze the memory down, and work through the DP interview questions pattern by pattern.
- 5 Lessons
- 21 Problems
- 50 Illustrations
What you will learn
- What dynamic programming is: overlapping subproblems and optimal substructure
- Top-down memoization and bottom-up tabulation, and the order each one visits the subproblems
- How much memory a DP uses, and how to cut it from a full table to a row or a few variables
- A recipe for any DP question: the state, the recurrence, the base cases and the order
- 5 patterns: 1D DP, grid DP, knapsack, sequences and strings, and state machines and intervals
- The dynamic programming interview questions asked most, from Climbing Stairs to Burst Balloons
Why this course
Dynamic programming is recursion that remembers. When a brute-force search keeps solving the same smaller problems again and again, storing each answer the first time turns exponential time into polynomial time.
The introduction shows how DP works — from a slow recursion to memoization (top-down) and tabulation (bottom-up), the order each one fills in the answers, and how to make the table use less memory — with a drawing and a simulator for each.
Then come 5 patterns, from easiest to hardest, each taught through the interview questions that use it, with code in four languages, the time and space of every approach and a simulator that fills the table step by step.
Requirements
- Comfort writing functions, loops and arrays in at least one language
- The Recursion & Backtracking course, or comfort with recursive functions
- 2D arrays for the grid and string patterns
Course Contents
2. Pattern 1 · 1D DP
3. Pattern 2 · Grid DP
4. Pattern 3 · Knapsack
5. Pattern 4 · Sequences and strings
6. Pattern 5 · State machines and intervals
Related courses
- Recursion & BacktrackingBreaking problems into smaller versions of themselves, and undoing choices that don't work out.5 lessons · 20 problems
- ArraysContiguous, indexable memory — the foundation almost every other data structure builds on.12 lessons · 16 problems
- StringsCharacter arrays with their own set of classic patterns — two pointers, sliding window, and more.5 lessons · 26 problems
