Greedy Choice Property

When searching for a possible solution to a problem, we usually consider various solutions, which we call the solution space.

When trying to find the best solution to a problem, we're usually interested in a global optimum, that is, the optimal solution from the whole set of possible solutions.

However, the solution space can exhibit other optimums. Namely, we can have local optimums, which are optimal solutions in a small neighborhood of possible solutions.

The greedy choice property states that from a local optimum we can reach a global optimum, without having to reconsider decisions that have already been made.

In the activity selection problem for Peter, we applied the greedy choice by always choosing the activity with the earliest finish time from the set of available activities.

Intuitively, we can think that this problem exhibits the greedy choice property in the sense that if we have a maximum size subset and we replace the activity from that set with the earliest finish time with one that finishes even earlier, we are always left with a maximum size set, making it safe to always choose the one with the earliest finish time.

It is possible to prove that the greedy choice is always part of some optimal solution.

Let's try to prove that, for any nonempty subproblem Sk, if am is an activity in Sk with the earliest finish time, then am is included in some maximum size subset of mutually compatible activities of Sk.

To prove it, let's assume the following:

  • Ak is a maximum size subset of mutually compatible activities in Sk
  • aj is the activity in Ak with the earliest finish time

If aj = am, we are done. If aj != am, we can try to replace aj by am in Ak, producing the set A'k = Ak - {ak} ∪ {am}.

We can safely do that since the activities in Ak are disjoined. aj is the first activity to finish in Ak, and fm <= fj.

Since |A'k| = |Ak|, we conclude that A'k is a maximum size subset of mutually compatible activities of Sk, and that it includes am.

Intuition usually helps us decide whether a greedy algorithm produces the optimal solution, without having to formally prove the optimal substructure and the greedy choice properties. We're also going to cover a different paradigm of algorithm design in this chapter, which is dynamic programming that also requires problems to exhibit the optimal substructure property. If you are not sure if a greedy algorithm works for a given problem due to the greedy choice, you can always build a dynamic programming solution for it to gain some insight.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.245.167