Greedy Problem List
Greedy Problem List
A Simple Solution is to generate all subsets of given set of jobs and check individual subset for
feasibility of jobs in that subset. Keep track of maximum profit among all feasible subsets. The
time complexity of this solution is exponential. This is a standard Greedy Algorithm problem.
Input : L = {1, 2, 3, 5, 6}
T = {2, 4, 1, 3, 2}
Output : 3, 5, 4, 1, 2
Explanation: We should complete jobs
3, 5, 4, 1 and then 2 in this order.
Let us consider two extreme cases and we shall deduce the general case solution from them.
1. All jobs take same time to finish, i.e. Ti = k for all i. Since all jobs take same time to finish
we should first select jobs which have large Loss (Li). We should select jobs which have
the highest losses and finish them as early as possible. Thus this is a greedy algorithm.
Sort the jobs in descending order based on Li only.
2. All jobs have the same penalty. Since all jobs have the same penalty we will do those jobs
first which will take less amount of time to finish. This will minimize the total delay, and
hence also the total loss incurred. This is also a greedy algorithm. Sort the jobs in
ascending order based on Ti. Or we can also sort in descending order of 1/Ti.
From the above cases, we can easily see that we should sort the jobs not on the basis of Li or Ti
alone. Instead, we should sort the jobs according to the ratio Li/Ti, in descending order.