Question

If an optimization problem can be solved using the greedy method, is it true that all its optimal solutions must always contain the first choice (i.e. the greedy choice)?

Was it helpful?

Solution

I am interpreting your question as "the set of all optimal solutions must always contain the first choice" otherwise it does not make sense for a solution to contain another solution.

Naturally, the answer is trivially yes. If a greedy algorithm solves the problem, it produces an optimal solution, which by definition is in the set of optimal solutions.

Perhaps you meant "if a greedy algorithm sometimes produces an optimal solution, ..." in that case again the answer is trivial.

If you meant that "if a greedy algorithm sometimes produces an optimal solution, is it true that all guaranteed optimal algorithms will produce that solution too?" the answer depends upon whether the problem has a unique optimal solution or multiple ones.

If a problem has multiple optimal solutions, the answer is clearly no.

A good example to think about is to sort a list of numbers such that all single digit numbers come ahead of two digit numbers, two digit numbers come ahead of three digit numbers, and so forth. I. e. you don't care whether 99 comes before 11 or vice versa, you just want 9 to come before 25, and 33 before 872, and 555 before 1234.

This example problem has multiple optimal solutions. A lazy but not greedy algorithm would not ensure that 11 comes before 99. An overenthusiastic algorithm would do so. Both would produce optimal solutions different from each other.

If this doesn't help, nothing will ;-)

OTHER TIPS

A greedy algorithm is an algorithm that follows the problem solving heuristic of making the locally optimal choice at each stage[1] with the hope of finding a global optimum. In many problems, a greedy strategy does not in general produce an optimal solution, but nonetheless a greedy heuristic may yield locally optimal solutions that approximate a global optimal solution in a reasonable time. Greedy algorithms mostly (but not always) fail to find the globally optimal solution, because they usually do not operate exhaustively on all the data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top