07 Dynamic Programming

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

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

View Full Document Right Arrow Icon
Dynamic Programming, Part 1 15-211 Fundamental Data Structures and Algorithms Margaret Reid-Miller 02 February 2010 Reading for today: Section 7.6
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
3 Today’s outline A Greedy Algorithm Dynamic Programming (DP) Example: Making change Aside: Memoization Other DP examples
Background image of page 3

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

View Full DocumentRight Arrow Icon
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 = ???
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 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
Background image of page 7

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

View Full DocumentRight Arrow Icon
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?
Background image of page 8
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 ?
Background image of page 9

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

View Full DocumentRight Arrow Icon
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
Background image of page 10
Image of page 11
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 Right Arrow Icon
Ask a homework question - tutors are online