[Math] Definition of a Greedy Algorithm

algorithms

Consider the following optimization problem:

We have n skiers with increasing heights $p_1,…,p_n$ and n skis with increasing heights $s_1,…,s_n$.
We want to minimize the average difference between the height of a skier and his assigned ski.
That is, if skier $p_i$ is assigned $s_{a(i)}$ we want to minimize:
$$\frac1n \sum_{i=1}^n(|\,p_i-s_{a(i)}\,|)$$

(a) Consider the following greedy algorithm. Find the skier and ski whose height di fference is minimized. Assign this skier this ski. Repeat the process until every skier has a ski. Prove of disprove
that this algorithm is correct.

(b) Consider the following greedy algorithm. Give the shortest skier the shortest ski, give the second
shortest skier the second shortest ski, give the third shortest skier the third shortest ski, etc.
Prove of disprove that this algorithm is correct.
HINT: One of the above greedy algorithms is correct and one is incorrect for the other. The proof of
correctness must be done using an exchange argument.

I had thought that a greedy algorithm was supposed to pick the optimal choice at each step. So, (a) would clearly be a greedy algorithm (even though it is not optimal).

However, I don't understand why (b) is a greedy algorithm. It is optimal, but it does not make the optimal choice at each step. Could someone clarify?

Best Answer

As Brian Tung writes in a comment, "greedy algorithm" is not really a crisp technical term, but more of a fuzzy concept that can be helpful for remembering and categorizing algorithms in your mind, and for getting ideas for how to possibly approach a new problem. There are essentially no cases where it makes any technical difference whether you call this-or-that algorithm greedy or not.

That being said, I wouldn't call algorithm (b) a "greedy algorithm" myself, but it's not completely crazy to do so either.

In general, if I were to describe what a greedy algorithm means, my first attempt would be something on the lines of

An algorithm that constructs a solution in little steps, where each step is chosen among the possible step at each time, based on a simple rule to identify which possibility makes the most immediate progress towards the eventual goal.

That certainly describes algorithm (a) -- the rule is simple and selects the way to increase the number-of-skis delivered that leads to the smallest value so far for the sum we want to minimize. That's a reasonable way to measure immediate progress.

On the other hand, if I want to shoehorn (b) into the "greedy paradigm" I would need to weaken my description into

An algorithm that constructs a solution in little steps, where each step is chosen among the possible step at each time, based on a simple rule.

The rule in algorithm (b) is surely simple enough, but it's hard to justify the rule as a short-sighted way to find the most immediate progress -- unless we cheat and already know that the rule happens to construct an optimal solution anyway.

On the other hand, algorithms that match the weakened desciption still have some relevant features in common with actual greedy algorithms -- among which is that the tactics that are useful for proving greedy strategies optimal (when they are indeed optimal), such as exchange arguments, can also be useful to reason about the wider group of algorithms.

So in this sense it is "not completely crazy" to describe (b) as a greedy algorithm, because it can still point towards useful ways to think and reason about the algorithm.