Approximate overview
Other good things
Sam, did you screw up on the design of problem 3?
Yes. I think so. I can’t fix it quickly. So problem 3 is cancelled. Sorry student who spent 3 hours on the problem. It’s good to try impossible things.
How do we approach the problem?
It doesn’t always work
Can we prove that it’s correct for US coins?
Let’s assume coins are 1, b, b^2, b^3, … b^k
How many coins do we need? We’ll use g[i] for the number of the b^i coin we need.
Greedy algorithm: A = g[k]b^k + g[k-1]b^(k-1) + …
Optimum algorithm: A = o[k]b^k + o[k-1]b^(k-1) + ….
What is the most number of any value that you would want? E.g., if we have pennies, nickles, and quarters, how many nickles would we want?
If we generalize …
Question: If I use b-1 of each of the first i coins, how much money do I have?
(b-1)b^0 + (b-1)b^1 + (b-1)b^2 + ... + (b-1)b^(i-1)
Factor out (b-1)
(b-1)(b^0 + b^1 + b^2 + ... + b^(i-1))
What’s the second sum? We look up geometric sums
(b^(i-1+1) - 1)/(b-1)
So our overall sum is
((b-1)(b^(i-1+1) - 1))/(b-1)
= (b^i - 1)
Suppose o[k] < g[k] for some k. Choose the largest such k.
We have to make up b^k with smaller coins.
But the most we can reasonably make with smaller coins is (b^k - 1). Whoops!
Each activity has a start time and a stop time.
|-----| |------| |------|
|------| |------| |-----|
|----| |---------| |--------|
We can’t take an activity at the same as another activity.
How do we find the maximum number of activities we can take?
What would you optimize?
There’s a good intuition behind each of these. However, four of them are wrong. Can we do counter-examples? Sure
See whiteboard. Summary below.
Moral: Greedy algorithms don’t always work. Hand-waving arguments are often not enough.
How do we prove that approach C is correct? (It is correct.)
We’re going to compare the greedy solution to the optimal solution.
We know that there’s a point at which the two solutions diverge. That is, the optimal solution and the greedy solution choose different next activity
You are a burglar. Not the hamburglar.
You have a backpack that can hold up to k cubic centimetres of stuff.
You are in a warehouse.
In the warehouse are a variety of boxes. Each box has a value v[i], and size s[i]. Your backpack is magic! It can stretch to hold exactly k cubic centimeters (i.e., you don’t have to worry about layout).
Your goal: Get the most value for the size.
Greedy approaches
Find counter-examples for A, B, and C. (No, D is not correct.)
Counter example for A (smallest):
Counter example for B:
Counter example for C:
Damn! Maybe we should use exhaustive search (dynamic programming).