Chapter 9 of 10All chapters
Chapter 9 of 10
Algorithm strategies
Greedy, divide and conquer, dynamic programming.
Three approaches
Greedy takes the best immediate step and is fast but only sometimes correct. Divide and conquer splits, solves and combines. Dynamic programming builds up answers to overlapping subproblems.
- Greedy works when a local best is provably part of a global best.
- Dynamic programming applies when subproblems repeat, which is what memoisation exploits.
Recognising the shape
Most interview problems are one of a dozen shapes: two pointers, sliding window, hash map counting, graph traversal, or a dynamic programming table. Recognising the shape is most of the work.