i2tutorials

DAA- Job Sequencing With Deadlines

Job Sequencing With Deadlines

 

Here is the process of Job sequencing in brief.

 

The problem states-

Approach to Solution

 

Greedy Algorithm Approach- 

We adopt the greedy algorithm inorder to determine the selection of the next job to get an optimal solution.

Below is the greedy algorithm that is always supposed to give an optimal solution to the job sequencing problem.

Step-01:
Step-02: 
Step-03: 

 

Algorithm for Job Sequencing with Deadline:

Algorithm: Job-Sequencing-With-Deadline (Dead, Job, n, k) 

Dead(0) := Job(0) := 0 
k := 1 
Job(1) := 1   // means first job is selected 
for i = 2 … n do 
   r := k 
   while Dead(Job(r)) > Dead(i) and Dead(Job(r)) ≠ r do 
      r := r – 1 
   if Dead(Job(r)) ≤ Dead(i) and Dead(i) > r then 
      for l = k … r + 1 by -1 do 
         Job(l + 1) := Job(l) 
         Job(r + 1) := i 
         k := k + 1 

 

PROBLEM BASED ON JOB SEQUENCING WITH DEADLINES-

Problem- 

We are given the jobs, their deadlines and associated profits as shown-

JobsJ1J2J3J4J5J6
Deadlines533242
Profits201181191301121101

 

Answer the following questions-

  1. Write the optimal schedule that provides us the maximum profit.
  2. Can we complete all the jobs in the optimal schedule?
  3. What is the maximum earned profit?

 

Solution:

Step-01:

Firstly, we need to sort all the given jobs in decreasing order of their profit as follows.

JobsJ4J1J3J2J5J6
Deadlines253342
Profits300200190180120100

Step-02:

For each step, we calculate the value of the maximum deadline.

Here, the value of the maximum deadline is 5.

So, we draw a Gantt chart as follows and assign it with a maximum time on the Gantt chart with 5 units as shown below.

Now,

Step-03: 

 

 

Step-04:

Step-05:

Step-06:

 

Step-07:

Now,

Now, the questions given above can be answered as follows:

 

Part-01: 

The optimal schedule is-

Job2, Job4, Job3, Job5, Job1

In order to obtain the maximum profit this is the required order in which the jobs must be completed.

Part-02: 

Part-03: 

Maximum earned profit = Sum of the profit of all the jobs from the optimal schedule

= Profit of job2 + Profit of job4 + Profit of job3 + Profit of job5 + Profit of job1

= 181 + 301 + 191 + 121 + 201

= 995 units

 

Analysis of the algorithm:

In the job sequencing with deadlines algorithm, we make use of two loops, one loop within another. Hence, the complexity of this algorithm would be O(n2).

 

Exit mobile version