[WPI] [cs2223] [cs2223 text] [News] [Syllabus] [Classes]
cs2223, D97/98 Class 18
Dynamic Programming
Dynamic programming is a way of optimizing some value or "cost".
A key element is the use of recursion to reduce the calculation time required
to perform the optimization. Several steps are involved in using dynamic
programming algorithms to solve problems.
- Select a numerical cost function which is to be optimized. It is important
to use a function which can be defined recursively.
- Write a recursive program which calculates and stores intermediate
optimal cost values. This function can calculate an exhaustive table of
values, as in the change algorithm shown in Section 8.2 of the text, or it can calculate the values only
as needed, as shown in the fibonacci sequence algorithm in Class
17.
- Devise and implement an algorithm for selecting the optimal cost.
- Devise and implement a method for determing the path by which the optimal
cost was obtained. This can be done by finding an algorithm for regenerating
the path from the cost or by creating an additional array with information
about how each value in the cost table was derived.
We demonstrated this process with the example of the change algorithm
shown in Section 8.2 of the text. Note
that some modifications of this algorithm may be required if there is no
unit coin in the coinage system.
Contents ©1994-1998, Norman Wittels
Updated 10Apr98