Dynamic Programming: Key Parts
Dynamic Programming: Key Parts
You're sitting at the public park on a beautiful summer day (as days usually are when you make them up in your head), minding your own business when out of nowhere a gigantic dog comes barreling towards you. No, really. This thing looks like a cross between an Irish wolfhound and a great white shark.
"Oh, don't worry," says the owner from too far away to save you. "Hercules is friendly, just a big old teddy bear."
Bears eat people sometimes. That's not comforting at all. Why would they think that's comforting?
In the end, though, Hercules just slobbers all over your face and book (hopefully it wasn't a signed first edition or anything). You may never get your money's worth on that book now, but good old Herc-y is friendly and safe, despite how terrifying he looked.
Just like your new best canine friend, dynamic programming might look intimidating at first glance. It also isn't really so bad once you get to know it (gross dog spit aside).
There are a couple of ways to solve a dynamic programming problem, meaning that you'll need to figure out which approach is the best choice for your problem. You could
- break the problem down.
- define the substructure of an optimal solution.
- generate a bottom up solution.
If that isn't your style, though, you could
- solve the problem recursively (if possible).
- memoize (store) intermediate solutions to a top-down solution.
Let's walk through how to decide which one to use. (Click on the buckets below for more.)
Dog treats sold separately.