3

Is there a greedy algorithm possible for this problem. I have worked out a DP algorithm for it but am not sure of a Greedy Algorithm for it. Please Explain if a greedy algorithm exists for it.

For those who are not familiar with the problem:

There are 'n' activities from a1 to an . Each activity ai has an associated start time si and a finish time fi i.e [si,fi). Each activity ai also has a value vi associated with it. No two activities can occur simultaneously. Task is to select mutually compatible activities so as to maximize the total value i.e summation of all activities scheduled. Mutally compatible means that their running times don't overlap.

KFkf
  • 175
  • 13
KayEs
  • 135
  • 8

1 Answers1

0

To find a greedy solution for a problem, we have to find a the intuition behind it. This problem looks similar to the problem of activity-selection problem in the text of CLRS (section 16.1). In that problem, we are to find a set with the maximum size in which every activities are mutually compatible. But this problem has another goal which wants us to find a set maximizing the coverage or resource usage.

The solution to this problem, in my opinion, is to first sort all activities based on their starting time. The intuition behind it is that we want to use the time/value/resources as fast as possible and not waste anything. Then, we start picking the longest activities and check if it is compatible with other activities that have been selected so far. And you continue picking up to the end. If you apply this to the example in the book, it gives you a set with activities {3, 7, 11}.

It might not be correct for all sets of activities. For example, a set of two activities: activity(1) = <0, 2> and activity(2) = <1, 5>.

As you can see, the idea doesn't work in this case. So you have to apply it again but from right to left. (Sort them based on their finishing times and pick those first which are finished first and lasted longer!) At the end you will pick the set with the most coverage!

I might not yet yield the best results. If we add another activity activity(3)=<4, 6>, those approaches are not the answers. So sorting activities based on their length in a descending order might be the answer.

At the end, one of these three approaches should give the answer.

Habib Karbasian
  • 556
  • 8
  • 18