Algorithms and OOD (CSC 207 2014S) : Outlines

# Outline 48: Dynamic Programming

Held: Friday, 25 April 2014

Back to Outline 47 - Heap Sort. On to Outline 49 - Project Presentations.

Summary

We consider a new approach to solving certain kinds of complex problems.

Related Pages

Overview

• Fibonacci.
• Generalizing the idea.
• The stamps problem.
• Edit distance in strings.

• Don't forget to turn in tutor/mentor/grader forms.

### Upcoming Work

• Today's writeup: No writeup.
• Part 2 of the project is due tonight at 10:30 p.m. (No, I'm not updating the Web page.)
• Please be careful on formatting!
• Please be careful on citations!

### Extra Credit

• CS Table today: Heartbleed.
• Iowater project April 26 - Tag drains. Mail iowater@grinnell.edu for details.

## Fibonacci

• Recursive formulation
• Improving the solution
• Cache the results in a table!
• Making it iterative
• Fill in the table from left to right
• Making it even better
• Only need two variables

• Tables!

## The Stamps Problem

• Given some set of stamp values and a desired value, find the fewest stamps to make that value.
• E.g., 1, 2, 7, 12, 25
• Recursive formulation
• Making it iterative
• Use a table and fill it in left-to-right

## The Edit Distance Problem

• What's the fewest number of edits (insertions, deletions) necessary to transform one string to another?
• Once again, there's a nice recursive formulation.
• Can we use similar techniques to make it iterative?
• This time, we need a two-dimensional table.
• Columns: Letters of source string
• Rows: Letters of target string
• Moving left represents deletion
• Moving up represents insertion
• And yes, we should fill it in iteratively

Copyright (c) 2013-14 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit `http://creativecommons.org/licenses/by/3.0/` or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.