Dynamic programming
A strategy that splits a problem into subproblems that repeat and stores each one's solution so it is never computed twice.
Example
Fibonacci of 40 with plain recursion makes over 300 million calls; storing each result, it takes 40 steps.
Test yourself: Dynamic programming
Dynamic programming
Climbing 1 or 2 stairs at a time, a 3-stair staircase can be climbed in ___ ways.
1 + 1 + 1, 1 + 2 and 2 + 1: that is 3 ways, and dp[3] = dp[2] + dp[1] = 2 + 1 = 3.
Dynamic programming
Building a wall from the first row of bricks upward is like going from the ___ up.
Each row rests on the one below, which is already there: with 10 rows, 10 steps, without going back.
Dynamic programming
Since dp[i] only uses the previous 2, ___ variables are enough.
With a = 3 and b = 5, the next is a + b = 8, and they shift: a = 5, b = 8. For n = 1,000, 2 variables instead of 1,000.
0/3
â–¶ PlayLessons that use it
Time complexity
Count steps, not seconds
Divide and conquer
Split, solve and combine
Backtracking
Try, and if it fails, go back
Dynamic programming
Solve each thing only once
When DP works
3 properties
Solving with DP
State, transition and borders
0-1 knapsack
Take it or leave it
Edit distance
How many changes separate 2 words
Greedy algorithms
The best right now
Fractional knapsack
Most value per kilo
