The document describes an algorithm for job sequencing with deadlines. It takes as input the deadline array D and job array J of size n. It assigns jobs to time slots T while respecting the deadlines, with the goal of maximizing profit. The algorithm initializes the time slots to empty, then iterates through jobs to find the earliest slot k meeting the deadline and assigns the job if the slot is empty, else moves to the next slot. This produces a job sequence with maximum profit respecting all deadlines. An example is provided to illustrate the algorithm.
2. Algorithm stated
1. Algorithm JS(d,j,n)
2. {
3. D[0] : =T[0] : =0; / * This fictious job allows easy insertion into position 1 of time slot*/
4. T[1] : =1; / *assigning job 1 to time slot*/
5. k:=1;
6. For i:=2 to n do
7. {
8. r:=k;
9. while((D[T[r]]>D[i]) and (D[T[r]]!=r))do r:=r-1;
10. if ((D[T[r]]<=D[i]) and (D[i]>r))then
11. {
12. for q:=k to (r+1) step-1 do T[q+1]:=T[q]; /*”step-1” implies making the
consecutive slots empty*/
13. T[r+1]:= i; k:=k+1;
14. }
15. }
16. Return k;
17. }
4. Now , we give index to jobs: n=5
i
Index 1 2 3 4 5
Jobs J1 J2 J3 J4 J5
Profits 20 15 10 5 1
Deadline 2 2 1 3 3
5. The maximum deadline given for a job in the egs is:
3.
Hence, Dmax=3.
So we can get a maximum of 3 time slots(initially-1 job-
1 unit of time).
Henceforth , we create a table for time slot ,T:
Timeslot 1 2 3
Status
6. From the algo we are solving the problem:
Look at index 1 of job array , its deadline is 2 ,tf it has to
come in the first slot.
Now, assigning i=1 =>J1 to timeslot array, T[].
Then , assigning other slots to be Empty[-1].
T[1] : =1; / *assigning job 1 to time slot*/
for q:=k to (r+1) step-1 do T[q+1]:=T[q]; /*”step-1” implies making
the consecutive slots empty*/
T[r+1]:= i; k:=k+1;
Table will be now,
7. Now , i becomes 2
Formula of k is min(Dmax, deadline(i))
k checks which is the min among the values
k =min(3,2)=2;
Checking if k>=1.
The solution is a yes .
Hence, checking timeslot(k)==-1or empty
If yes fill it with the corresponding job.
Now , i becomes 3
Formula of k is min(Dmax, deadline(i))
k checks which is the min among the values
k =min(3,1)=1;
Checking if k>=1.
The solution is a yes .
Hence, checking timeslot(k)==-1or empty
It’s a no,hence decrementing k by 1 and j3 rejected.
8. Now , i becomes 4
Formula of k is min(Dmax, deadline(i))
k checks which is the min among the values
k =min(3,3)=3;
Checking if k>=1.
The solution is a yes .
Hence, checking timeslot(k)==-1or empty
If yes fill it with the corresponding job.(j4)
Now , i becomes 5
Formula of k is min(Dmax, deadline(i))
k checks which is the min among the values
k =min(3,3)=3;
Checking if k>=1.
The solution is a yes .
Hence, checking timeslot(k)==-1or empty
It’s a no, hence decrement k by 1 and reject j5 and exit for
loop.
9. Final timeslot table results give a sequece of jobs with max
profit which meet the deadlines.
Therefore the sequence of jobs is :
J1->J2->J4