461 views
0 votes
0 votes

i am getting 100+35+50=185 is it correct ???

2 Answers

0 votes
0 votes

Always put maximum profit job as farthest as possible. Sort them according to their profit and total time is maximum in deadline.

Job J2 J3 J5 J1 J4
Deadline 1 2 1 3 2
Profit 100 50 35 25 25

Now as you can see J2 is having highest profit and it should be completed in 1st time slot(not after that).

So first take J2 for time slot 1. after that J3 is having highest profit and it will complete in 2nd time slot. (J3 can be completed before 2 but not after that) now J5 can't be completed because 1 slot is already taken by J2 so only J1 can execute in 3rd time slot.

So total profit= 100+50+25 =175

 

0 votes
0 votes

first short the jobs with respect to their profit

                        j2,j3,j5,j4=j1

And short jobs with respect to their deadline early job first

                       j2=j5,j3=j4,j1

initialize a variable profit=0, and a stack for holding done jobs.

step 1: Take max profit job with minimum deadline (means early job).

stack=j2

profit=100

step 2: Take next max profit job in remaning with minimum deadline (means early job).

stack=j2,j3

profit=100+50

step 3: Take next max profit job in remaining with minimum deadline (means early job).

stack=j2,j3,j1

profit=100+50+25

final profit is 175

 

 

 

Related questions

0 votes
0 votes
0 answers
1
gateexplore asked Oct 25, 2023
132 views
It is always true that Recursive code is easier to debug?? If yes then why?? please give full explanation.