160
Chapter 8
I
Greedy algorithms
Recap
• Greedy algorithms optimize locally, hoping to end up with a global
optimum.
• NP-complete problems have no known fast solution.
• If you
have an NP-complete problem, your best bet is to use an
approximation algorithm.
• Greedy algorithms are easy to write and fast to run,
so they make
good approximation algorithms.
161
In this chapter
• You learn dynamic programming, a
technique
to solve a hard problem by
breaking it up into subproblems and
solving those subproblems first.
• Using examples,
you learn to how to come up
with a dynamic programming solution to a
new problem.
dynamic
programming
9
The knapsack problem
Let’s revisit the knapsack problem from chapter 8.
You’re a thief with a knapsack that can carry 4 lb
of goods.