07 Dynamic Programming

# 07 Dynamic Programming - Dynamic Programming, Part 1 15-211...

This preview shows pages 1–11. Sign up to view the full content.

Dynamic Programming, Part 1 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller 02 February 2010 Reading for today: Section 7.6

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Announcements HW 2 is available Theory: due in class Tuesday, Feb 9 Snake program: due Thursday, Feb 11 Quiz 2 is tomorrow in recitation You must go to your own recitation! Quiz 1 & HW 1 theory will be returned in recitation
3 Today’s outline A Greedy Algorithm Dynamic Programming (DP) Example: Making change Aside: Memoization Other DP examples

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Time for change? Suppose you have an unlimited supply of pennies, nickels, dimes, and quarters: How do you make change for some target amount x ? e.g. x = 65 cents x = 80 cents x = 43 cents x = ???
5 More precisely, how do you write x as a non-negative linear combination of d 1 = 1, d 2 = 5, d 3 = 10, d 4 = 25 ? x = x 1 d 1 + x 2 d 2 + x 3 d 3 + x 4 d 4 , where x ε N For example: 20 = 4 5 + 0 10 + 0 25 Other solutions: Making change 20 = 2 5 + 1 10 20 = 2 10

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Problem variants There are several computational problems hiding here: Decision: Determine whether there is a solution. Counting: Determine how many solutions there are. Enumeration: Generate all solutions. Search: Find an arbitrary solution if it exists, NO otherwise. The problems are related: Any algorithm for Enumeration also solves the Counting problem, which in turn solves the Decision problem. 6
Optimization problem A common variant is to find a solution that optimizes some property: Min-Search : Find a solution that minimizes the number of coins used. Even though it may seem that this is a harder problem, often the extra constraint helps reduce the search space: There are few degrees of freedom. 7

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
8 Making change algorithm An easy algorithm for giving out x cents in change: Choose the largest coin that is x . Subtract the value of the chosen coin from x , to get a new value of x . Repeat until a total of x cents has been counted. Does this work? I.e., does this really give out the minimal number of coins?
9 Making change algorithm For US currency, this simple algorithm actually works. Exercise: Prove this algorithm is correct for pennies, nickels, dimes, and quarters Why do we call this a greedy algorithm ?

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Greedy algorithms At every step, a greedy algorithm makes a choice that currently seems best (locally optimal), with the idea that in the end it all adds up to a globally optimal solution. Being optimistic like this usually
This is the end of the preview. Sign up to access the rest of the document.

## This document was uploaded on 05/10/2011.

### Page1 / 48

07 Dynamic Programming - Dynamic Programming, Part 1 15-211...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online