DAA Assign 2
DAA Assign 2
: 2
Write a program to implement job sequencing with deadline using greedy method
Software: Turbo C
In job sequencing with deadlines problem, the objective is to find a sequence of jobs
completed within their deadlines, giving a maximum profit. Let us consider the set of n
given jobs associated with deadlines, and profit is earned if a job is completed by its
deadline. These jobs need to be ordered so that the maximum profit is earned.
dDesign and Ana
Pseudo code
for i = 1 to n do
Set k = min(dmax, DEADLINE(i)) //where DEADLINE(i) denotes deadline of ith job
while k >= 1 do
if timeslot[k] is EMPTY then
timeslot[k] = job(i)
break
endif
Set k = k - 1
endwhile
endfor
Program :
#include <stdio.h>
int main(void) {
//variables
int i, j;
//temp
Job temp;
//number of jobs
int n = 5;
return 0;
}
//required jobs
printf("\nRequired Jobs: ");
for(i = 1; i <= dmax; i++) {
printf("%s", jobs[timeslot[i]].id);
//required profit
maxprofit = 0;
for(i = 1; i <= dmax; i++) {
maxprofit += jobs[timeslot[i]].profit;
}
printf("\nMax Profit: %d\n", maxprofit);
}
Outpout:
Job Deadline Profit
j2 1 100
j1 2 60
j4 2 40
j3 3 20
j5 1 20
dmax: 3
Hence, we have implenment job sequencing with deadline in greedy method successfully.