0% found this document useful (0 votes)
8 views4 pages

AOA-Lab Exp4

The document outlines an experiment to implement a C program for the Job Sequencing with Deadlines problem, which aims to maximize profit by scheduling jobs within their deadlines. It describes the algorithm to sort jobs by profit and find feasible time slots for scheduling. The conclusion emphasizes the use of a greedy algorithm to solve the problem effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

AOA-Lab Exp4

The document outlines an experiment to implement a C program for the Job Sequencing with Deadlines problem, which aims to maximize profit by scheduling jobs within their deadlines. It describes the algorithm to sort jobs by profit and find feasible time slots for scheduling. The conclusion emphasizes the use of a greedy algorithm to solve the problem effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Name: Subrato Tapaswi Roll No.

/Div: 60/D6AD
EXPERIMENT-4

AIM:
Write a C program to implement Job sequencing with deadlines problem.
THEORY:
Given an array of jobs where every job has a deadline and associated profit if the job is finished before the
deadline. It is also given that every job takes a single unit of time, so the minimum possible deadline for any
job is 1. How to maximize total profit if only one job can be scheduled at a time.

We are given a set of n jobs. Associated with job i is an integer deadline di ≥ 0 and a profit pi ≥ 0. For any
job i the profit p, is earned if the job is completed by its deadline. To complete a job, one has to process the
job on a machine for one unit of time. Only one machine is available for processing jobs. A feasible solution
for this problem is a subset J of jobs such that each job in this subset can be completed by its deadline. The
value of a feasible solution J is the sum of the profits of the jobs in J, or Σi∈JPi. An optimal solution is a
feasible solution with maximum value.

Our goal is to find a feasible schedule S which maximizes the profit of scheduled job. The goal can be
achieved as follow: Sort all jobs in decreasing order of profit. Start with the empty schedule, select one job
at a time and if it is feasible then schedule it in the latest possible slot.

Complexity: Time Complexity: O(n2)


ALGORITHM:
1) Sort all jobs in decreasing order of profit.
2) Iterate on jobs in decreasing order of profit.For each job , do the following :
a. Find a time slot i, such that slot is empty and i < deadline and i is greatest.Put the job in
this slot and mark this slot filled.
b. If no such i exists, then ignore the job.

JS(d, j, n)
// di ≥ 1,1 ≤ i ≤ n are the deadlines,n≥1.
//The jobs 3 are ordered such that p[1] ≥ p[2]… ≥p[n]
//J[i] is the ith job in the optimal solution, 1≤ i ≤k
// Also, at termination d[J[i]] ≤ d[J[i+1]], 1 ≤ i <k
{
d[0]:=J[0] := 0; // Initialize.
J[1] := 1; // Include job 1.
k := 1;
for i:= 2 to n do
{
// Consider jobs in nonincreasing order of p[i].
// Find position for i and check feasibility of insertion.
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
{
// Insert i into J[]
for q:= k to (r+1) step -1 do J[g + 1]: = J[g];
J[r +1] := i ; k:=k + 1;
}
}
return k;
}

PROGRAM CODE:
OUTPUT:

CONCLUSION:
Thus, we have implemented the concept of greedy algorithm to solve the job sequencing with deadlines
problem.

You might also like