Activity Selection Problem
A problem for which a greedy algorithm does work and gives the optimal solution is the activity selection problem
. There is a weighted version of the same problem, discussed here, which cannot be solved using a greedy algorithm. However, its unweighted version that we discuss here can be solved optimally using a greedy strategy.
The activity selection problem involves a set of n
activities, each having a start and finish time. Some of these activities are overlapping. The objective is to select a maximum sized set of non-overlapping activities.
The following are the parameters of this problem:
n
is the total number of intervals- Array
s
andf
of sizen
to store the start and finish time of each activity s[j] < f[j]
forj = 0..(n-1)
- The arrays are sorted according to finish time values (in
f
array) in ascending order