3. Introduction
3
The objective is to find a sequence of jobs, which is completed within
their deadlines with maximum profit
Because we are using two loops one within another, the complexity of
this algorithm is O(n2)
4. Algorithm
4
Algorithm Job_seq (d, 1, n){
d [0] = 0;
JS [1] = 1;
i = 1;
for j= 2 to n do;{
k = i;
while ((d[JS[k] > d[j]]) and (d[JS[k]] != k)) do
k = k -1;
if ((d[JS[k] < d[j]]) and (d[j] > k)) then {
For m= i to (k+1) step-1 do
JS [m+1] = JS [m];
JS [K+1] = j;
i = i+1;
}
}
Return i;
}
1
1
1
n
1
2*n
2
2*n
n*n
1*n*n
1*n*n
2*n*n
Time complexity = O(n2)
5. Example
5
Value of maximum deadline = 5
• First, we take job J4.
• Since, its deadline is 2, so we
place it in the first empty cell
before deadline 2 as-
• Now, we take job J1.
• Since, its deadline is 5, so we
place it in the first empty cell
before deadline 5 as-
• Now, we take job J3.
• Since, its deadline is 3, so we
place it in the first empty cell
before deadline 3 as-
6. Example
6
Value of maximum deadline = 5
• Now, we take job J2.
• Since, its deadline is 3, so we
place it in the first empty cell
before deadline 3.
• Since, the second and third cells
are already filled, so we place job
J2 in the first cell as-
• Now, we take job J5.
• Since, its deadline is 4, so we
place it in the first empty cell
before deadline 4 as-
• The only job left is job J6 whose deadline is 2.
• All the slots before deadline 2 are already occupied.
• Thus, job J6 can not be completed.
• Maximum earned profit = Sum of profits of all jobs in optimal schedule
= Profit of job J2 + Profit of job J4 + Profit of job J3 + Profit of job J5 +
Profit of job J1
= 180 + 300 + 190 + 120 + 200
= 990 units