Comparing Greedy Solution from Class

We came up with a very interesting "greedy" solution in class where we try to take the highest coins away that we can first. This works perfectly well for the 1, 5, 10, and 25 cent coints we're used to using, but it doesn't work when we use some more exotic values. Let's compare a memoized version "make_change" to "make_change_greedy" that Kevin and Brendan came up with in class, using 1, 7, 10, and 25 cent coins:

As an example of where there's a disparity, we can see that making 41 cents should only take 5 steps: 4x10c + 1x1c. However, a greedy solution will first take 25 away, leaving 16. Then it will take 10 away, leaving 6. And the best it can do after that is 6x1c. So a greedy solution ends up taking 8 steps instead of 5!

By contrast, if we switch to ordinary coins, the greedy solution works just the same. But this is a cautionary tale about greedy solutions in general; sometimes we take steps that look good in the near term, but they end up trapping us into taking non-optimal steps later