64% found this document useful (11 votes)
23K views

Write A Program To Implement Job Sequencing Algorithm

This C program implements the greedy job sequencing algorithm to determine the optimal order of jobs to maximize total profit. It takes job deadline and profit values as input, sorts the jobs in decreasing order of profit/deadline ratio, and outputs the highest profit job sequence. The algorithm runs in O(n^2) time complexity where n is the number of jobs.

Uploaded by

Tarun Agarwal
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
64% found this document useful (11 votes)
23K views

Write A Program To Implement Job Sequencing Algorithm

This C program implements the greedy job sequencing algorithm to determine the optimal order of jobs to maximize total profit. It takes job deadline and profit values as input, sorts the jobs in decreasing order of profit/deadline ratio, and outputs the highest profit job sequence. The algorithm runs in O(n^2) time complexity where n is the number of jobs.

Uploaded by

Tarun Agarwal
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Write a program to implement job sequencing algorithm using greedy

approach.

#include<stdio.h>
#include<conio.h>
int jobsequence(int d[6],int j[6],int n)
{
int q,i,r,k;
d[0]=0;
j[0]=0;
j[1]=1;
k=1;
for(i=2;i<=n;i++)
{
r=k;
while((d[j[r]]>d[i]) &&(d[j[r]]!=r))
r=r-1;

if((d[j[r]]<=d[i]) && (d[i]>r))


{
for(q=k;q>=r+1;q--)
{
j[q+1]=j[q];
}
j[r+1]=i;
k=k+1;
}
}

return k;
}
void main( )
{
int d[6],j[6],p[6],k,i;
clrscr( );
printf("Enter the deadlines :");
for(i=1;i<=5;i++)
scanf("%d",&d[i]);
printf("Enter the profits :");
for(i=1;i<=5;i++)
scanf("%d",&p[i]);
for(i=1;i<=5;i++)
j[i]=i;
k=jobsequence(d,j,5);
printf("\nThe solution job sequence is ");
for(i=1;i<=k;i++)
printf("\n%d",j[i]);
getche( );
}

OUTPUT

Enter the deadlines :2


2
1
3
3
Enter the profits :18
14
12
5
1

The solution job sequence is


1
2
4

Complexity :-

You might also like