-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathJob Sequencing Problem
30 lines (24 loc) · 1.3 KB
/
Job Sequencing Problem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
greedy algorithm
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.
Example:
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) Initialize the result sequence as first job in sorted jobs.
3) Do following for remaining n-1 jobs
.......a) If the current job can fit in the current result sequence
without missing the deadline, add current job to the result.
Else ignore the current job.
Time Complexity of the above algo is O(n2).