Algorithms

Spring 2017
course
navigation

Feb 21

The homework for Thursday is posted.
The code that we wrote in class is attached ... with the memoization code fixed, after a Merlin & Jim discussion just after class.

making change

I'm going to go over the "making change" problem in our textbook, which has a lot of ideas in it.
It's similar to the last of the homework problems.
For each of the following methods, let's see if we can (a) understand the idea, and then (b) write some code (either based on the textbook or something we write in class).
This is a famous problem : https://en.wikipedia.org/wiki/Change-making_problem

greedy

The "greedy" approach: go as far as you can towards the goal in each step.
Example:
A good method ... which doesn't work for some coin systems.
A greedy failure : (1,3,4) are the coins, and you're asked to make 6. Greedy says (4, 1, 1) = 3 coins. But best is 2 coins ...

brute force

brute force approach: try every possibility, recursively.
This always works ... and is very, very slow.
Sketch out the tree of things to try and see how fast it grows.
The textbook has a nice graphic.

brute force with memoization

For this problem, this gets us there pretty quickly, since most of the repetitive branches are cut off because we remember what we've done before and don't repeat it.
We did an Fibonnacci example like this last week.

dynamic programming

The most elegant solution is to build up to the answer in small steps, finding answers to the problems along the way and keeping track of the best answer for each value.
The text walks through this approach, which we will do in class.
http://cs.marlboro.edu/ courses/ spring2017/algorithms/ notes/ Feb_21
last modified Tuesday February 21 2017 12:46 pm EST

attachments [paper clip]

     name last modified size
   coins.py Feb 21 2017 12:46 pm 2.01kB