By BYJU'S Exam Prep

Updated on: September 25th, 2023

Job Sequencing with Deadlines problem uses the greedy approach. So we have to find the best method/option in the greedy method out of many present ways. In this method/ approach, we focus on the first stage, decide the output, and don’t think about the future.

Many optimization problems can be determined using the greedy algorithm. Some issues have no efficient solution, but the greedy algorithm may provide a solution close to optimal. Here, we will briefly see the Job sequencing with deadlines definition, algorithm, and example.

## What is Job Sequencing with Deadlines?

In a 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.

It may happen that all the given jobs can not be completed within their deadlines. Assume that the deadline of ith job Ji is di and the profit received from job Ji is pi. Hence, the optimal solution of job sequencing with deadlines algorithm is a feasible solution with maximum profit.

### Points to Remember for Job Sequencing with Deadlines

• Each job has deadline di & it can process the job within its deadline; only one job can be processed at a time.
• Only one CPU is available for processing all jobs.
• CPU can take only one unit at a time for processing any job.
• All jobs arrived at the same time.

## Job Sequencing with Deadlines Algorithm

Suppose there are jobs J(i) with the deadline D(i) and profit P(i) where 0≤i≤1. These jobs are ordered according to profit p1⩾p2⩾p3⩾…⩾pn.

D(0) := J(0) := 0

k:= 1

J(1) := 1 // means first job is selected

for i = 2 … n do

r:= k

while D(J(r)) > D(i) and D(J(r)) ≠ r do

r:= r – 1

if D(J(r)) ≤ D(i) and D(i) > r then

for l = k … r + 1 by -1 do

J(l + 1): = J(l)

J(r + 1): = i

k:= k + 1

## Job Sequencing with Deadlines Example

Let us consider a given job sequencing problem, as shown in the table below. We have to find the sequence of jobs completed within their deadlines and give the maximum profit. Each job is associated with the deadline and profit as given below:

 Job J1 J2 J3 J4 J5 Deadline 2 1 1 2 3 Profit 40 100 20 60 20

The given jobs are sorted as per their profit in descending order to solve this problem. Hence, the jobs are ordered after sorting, as shown in the following table.

 Job J2 J4 J1 J5 J3 Deadline 1 2 2 3 1 Profit 100 60 40 20 20

From the given set of jobs, first, we select J2, as it should be completed within its deadline and contributes maximum profit.

• Next, J4 is selected as it gives more profit than J1.
• J1 cannot be selected in the next clock as its deadline is over. Hence J5 is selected as it executes within its deadline.
• Job J3 is discarded as it should not be executed within its deadline.

Therefore, the sequence of jobs (J2, J4, J5) is executed within their deadline and gives the maximum profit.

The total profit of the sequence is 100 + 60 + 20 = 180.

POPULAR EXAMS
SSC and Bank
Other Exams
GradeStack Learning Pvt. Ltd.Windsor IT Park, Tower - A, 2nd Floor, Sector 125, Noida, Uttar Pradesh 201303 help@byjusexamprep.com