Given an array of jobs where every job has a deadline and associated profit if the job is finished before the deadline. It is also given that every job takes single unit of time, so the minimum possible deadline for any job is 1. How to maximize total profit if only one job can be scheduled at a time.
Input: Four Jobs with following deadlines and profits JobID Deadline Profit a 4 20 b 1 10 c 1 40 d 1 30 Output: Following is maximum profit sequence of jobs c, a Input: Five Jobs with following deadlines and profits JobID Deadline Profit a 2 100 b 1 19 c 2 27 d 1 25 e 3 15 Output: Following is maximum profit sequence of jobs c, a, e
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. Following is algorithm.
1) Sort all jobs in decreasing order of profit.
2) Iterate on jobs in decreasing order of profit.For each job , do the following :
a)Find a time slot i, such that slot is empty and i < deadline and i is greatest.Put the job in
this slot and mark this slot filled.
b)If no such i exists, then ignore the job.
The Following is the implementation of above algorithm.
Following is maximum profit sequence of jobs c a e
Time Complexity of the above solution is O(n2). It can be optimized using Disjoint Set Data Structure. Please refer below post for details.
This article is contributed by Shubham. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Job Sequencing Problem | Set 2 (Using Disjoint Set)
- Job Sequencing Problem - Loss Minimization
- Job Selection Problem - Loss Minimization Strategy | Set 2
- Program for Shortest Job First (or SJF) CPU Scheduling | Set 1 (Non- preemptive)
- Program for Shortest Job First (SJF) scheduling | Set 2 (Preemptive)
- Job Scheduling with two jobs allowed at a time
- Shortest Job First (or SJF) CPU Scheduling Non-preemptive algorithm using Segment Tree
- Minimum time taken by each job to be completed given by a Directed Acyclic Graph
- Applications of Minimum Spanning Tree Problem
- N Queen Problem | Backtracking-3
- Activity Selection Problem | Greedy Algo-1
- Partition problem | DP-18
- The Stock Span Problem
- K Centers Problem | Set 1 (Greedy Approximate Algorithm)
- Set Cover Problem | Set 1 (Greedy Approximate Algorithm)
- Shortest Superstring Problem
- Fractional Knapsack Problem
- Max Flow Problem Introduction
- Fitting Shelves Problem
- Water Connection Problem