SlideShare a Scribd company logo
1 of 11
Algorithm analysis
and design
Job sequencing with deadlines.
Algorithm stated
1. Algorithm JS(d,j,n)
2. {
3. D[0] : =T[0] : =0; / * This fictious job allows easy insertion into position 1 of time slot*/
4. T[1] : =1; / *assigning job 1 to time slot*/
5. k:=1;
6. For i:=2 to n do
7. {
8. r:=k;
9. while((D[T[r]]>D[i]) and (D[T[r]]!=r))do r:=r-1;
10. if ((D[T[r]]<=D[i]) and (D[i]>r))then
11. {
12. for q:=k to (r+1) step-1 do T[q+1]:=T[q]; /*”step-1” implies making the
consecutive slots empty*/
13. T[r+1]:= i; k:=k+1;
14. }
15. }
16. Return k;
17. }
Example:
Q. Let n=5;p=(20,15,10,5,1);d=(2,2,1,3,3)
Ans:-
Given:
Jobs J1 J2 J3 J4 J5
Profits 20 15 10 5 1
Deadline 2 2 1 3 3
Now , we give index to jobs: n=5
i
Index 1 2 3 4 5
Jobs J1 J2 J3 J4 J5
Profits 20 15 10 5 1
Deadline 2 2 1 3 3
The maximum deadline given for a job in the egs is:
3.
Hence, Dmax=3.
So we can get a maximum of 3 time slots(initially-1 job-
1 unit of time).
Henceforth , we create a table for time slot ,T:
Timeslot 1 2 3
Status
From the algo we are solving the problem:
 Look at index 1 of job array , its deadline is 2 ,tf it has to
come in the first slot.
Now, assigning i=1 =>J1 to timeslot array, T[].
Then , assigning other slots to be Empty[-1].
T[1] : =1; / *assigning job 1 to time slot*/
for q:=k to (r+1) step-1 do T[q+1]:=T[q]; /*”step-1” implies making
the consecutive slots empty*/
T[r+1]:= i; k:=k+1;
Table will be now,
Now , i becomes 2
Formula of k is min(Dmax, deadline(i))
k checks which is the min among the values
 k =min(3,2)=2;
Checking if k>=1.
The solution is a yes .
Hence, checking timeslot(k)==-1or empty
If yes fill it with the corresponding job.
Now , i becomes 3
Formula of k is min(Dmax, deadline(i))
k checks which is the min among the values
 k =min(3,1)=1;
Checking if k>=1.
The solution is a yes .
Hence, checking timeslot(k)==-1or empty
It’s a no,hence decrementing k by 1 and j3 rejected.
Now , i becomes 4
Formula of k is min(Dmax, deadline(i))
k checks which is the min among the values
 k =min(3,3)=3;
Checking if k>=1.
The solution is a yes .
Hence, checking timeslot(k)==-1or empty
If yes fill it with the corresponding job.(j4)
Now , i becomes 5
Formula of k is min(Dmax, deadline(i))
k checks which is the min among the values
 k =min(3,3)=3;
Checking if k>=1.
The solution is a yes .
Hence, checking timeslot(k)==-1or empty
It’s a no, hence decrement k by 1 and reject j5 and exit for
loop.
Final timeslot table results give a sequece of jobs with max
profit which meet the deadlines.
Therefore the sequence of jobs is :
J1->J2->J4
•Algorithm that can
be prepared from
the example(for
easy
implementation)
1. Algorithm JS(D,J,n)
2. {
3. D[0] :=J[0] :=0;
4. for i:=1 to n
5. {
6. T[i]=-1;
7. }
8. J[1]:=1;
9. for i:=2 to n
10. {
11. k:= min(Dmax,D(i));
12. if(k>=1) then
13. {
14. if(T[k]==-1) then
15. {
16. T[k]:=J[k];
17. }
18. else
19. k--;
20. }
21. }

More Related Content

What's hot (20)

Optimal binary search tree dynamic programming
Optimal binary search tree   dynamic programmingOptimal binary search tree   dynamic programming
Optimal binary search tree dynamic programming
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
 
Introduction to NP Completeness
Introduction to NP CompletenessIntroduction to NP Completeness
Introduction to NP Completeness
 
Computability - Tractable, Intractable and Non-computable Function
Computability - Tractable, Intractable and Non-computable FunctionComputability - Tractable, Intractable and Non-computable Function
Computability - Tractable, Intractable and Non-computable Function
 
Backtracking
BacktrackingBacktracking
Backtracking
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
 
Bellman Ford's Algorithm
Bellman Ford's AlgorithmBellman Ford's Algorithm
Bellman Ford's Algorithm
 
Job sequencing in Data Strcture
Job sequencing in Data StrctureJob sequencing in Data Strcture
Job sequencing in Data Strcture
 
Tsp is NP-Complete
Tsp is NP-CompleteTsp is NP-Complete
Tsp is NP-Complete
 
Greedy method
Greedy method Greedy method
Greedy method
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
Daa
DaaDaa
Daa
 
Backtracking
Backtracking  Backtracking
Backtracking
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
implementation of travelling salesman problem with complexity ppt
implementation of travelling salesman problem with complexity pptimplementation of travelling salesman problem with complexity ppt
implementation of travelling salesman problem with complexity ppt
 
Branch & bound
Branch & boundBranch & bound
Branch & bound
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 

Similar to Algorithm analysis and design: Job sequencing with deadlines

time_complexity_list_02_04_2024_22_pages.pdf
time_complexity_list_02_04_2024_22_pages.pdftime_complexity_list_02_04_2024_22_pages.pdf
time_complexity_list_02_04_2024_22_pages.pdfSrinivasaReddyPolamR
 
Tucker tensor analysis of Matern functions in spatial statistics
Tucker tensor analysis of Matern functions in spatial statistics Tucker tensor analysis of Matern functions in spatial statistics
Tucker tensor analysis of Matern functions in spatial statistics Alexander Litvinenko
 
pradeepbishtLecture13 div conq
pradeepbishtLecture13 div conqpradeepbishtLecture13 div conq
pradeepbishtLecture13 div conqPradeep Bisht
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03Krish_ver2
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03Krish_ver2
 
Variations on the method of Coleman-Chabauty
Variations on the method of Coleman-ChabautyVariations on the method of Coleman-Chabauty
Variations on the method of Coleman-Chabautymmasdeu
 
Activ.aprendiz. 3a y 3b
Activ.aprendiz. 3a y 3bActiv.aprendiz. 3a y 3b
Activ.aprendiz. 3a y 3bCristian Vaca
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms ISri Prasanna
 
Analysis of Electro-Mechanical System
Analysis of Electro-Mechanical SystemAnalysis of Electro-Mechanical System
Analysis of Electro-Mechanical SystemCOMSATS Abbottabad
 
Copy of y16 02-2119divide-and-conquer
Copy of y16 02-2119divide-and-conquerCopy of y16 02-2119divide-and-conquer
Copy of y16 02-2119divide-and-conquerJoepang2015
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptxKokilaK25
 
Newton two Equation method
Newton two Equation  method Newton two Equation  method
Newton two Equation method shanto017
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfAmayJaiswal4
 
Ad2014 calvec-industrial-jllf.ps14000302.curvas (1)
Ad2014 calvec-industrial-jllf.ps14000302.curvas (1)Ad2014 calvec-industrial-jllf.ps14000302.curvas (1)
Ad2014 calvec-industrial-jllf.ps14000302.curvas (1)Angel David Ortiz Resendiz
 
Longest Common Sequence Algorithm Analysis
Longest Common Sequence Algorithm AnalysisLongest Common Sequence Algorithm Analysis
Longest Common Sequence Algorithm AnalysisRex Yuan
 

Similar to Algorithm analysis and design: Job sequencing with deadlines (20)

Unit 3 daa
Unit 3 daaUnit 3 daa
Unit 3 daa
 
time_complexity_list_02_04_2024_22_pages.pdf
time_complexity_list_02_04_2024_22_pages.pdftime_complexity_list_02_04_2024_22_pages.pdf
time_complexity_list_02_04_2024_22_pages.pdf
 
Tucker tensor analysis of Matern functions in spatial statistics
Tucker tensor analysis of Matern functions in spatial statistics Tucker tensor analysis of Matern functions in spatial statistics
Tucker tensor analysis of Matern functions in spatial statistics
 
Palm ch1
Palm ch1Palm ch1
Palm ch1
 
pradeepbishtLecture13 div conq
pradeepbishtLecture13 div conqpradeepbishtLecture13 div conq
pradeepbishtLecture13 div conq
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
algorithm Unit 3
algorithm Unit 3algorithm Unit 3
algorithm Unit 3
 
Variations on the method of Coleman-Chabauty
Variations on the method of Coleman-ChabautyVariations on the method of Coleman-Chabauty
Variations on the method of Coleman-Chabauty
 
Activ.aprendiz. 3a y 3b
Activ.aprendiz. 3a y 3bActiv.aprendiz. 3a y 3b
Activ.aprendiz. 3a y 3b
 
Text s1 21
Text s1 21Text s1 21
Text s1 21
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms I
 
Analysis of Electro-Mechanical System
Analysis of Electro-Mechanical SystemAnalysis of Electro-Mechanical System
Analysis of Electro-Mechanical System
 
Copy of y16 02-2119divide-and-conquer
Copy of y16 02-2119divide-and-conquerCopy of y16 02-2119divide-and-conquer
Copy of y16 02-2119divide-and-conquer
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 
Newton two Equation method
Newton two Equation  method Newton two Equation  method
Newton two Equation method
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
 
Laplace_1.ppt
Laplace_1.pptLaplace_1.ppt
Laplace_1.ppt
 
Ad2014 calvec-industrial-jllf.ps14000302.curvas (1)
Ad2014 calvec-industrial-jllf.ps14000302.curvas (1)Ad2014 calvec-industrial-jllf.ps14000302.curvas (1)
Ad2014 calvec-industrial-jllf.ps14000302.curvas (1)
 
Longest Common Sequence Algorithm Analysis
Longest Common Sequence Algorithm AnalysisLongest Common Sequence Algorithm Analysis
Longest Common Sequence Algorithm Analysis
 

Recently uploaded

The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 

Recently uploaded (20)

The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 

Algorithm analysis and design: Job sequencing with deadlines

  • 1. Algorithm analysis and design Job sequencing with deadlines.
  • 2. Algorithm stated 1. Algorithm JS(d,j,n) 2. { 3. D[0] : =T[0] : =0; / * This fictious job allows easy insertion into position 1 of time slot*/ 4. T[1] : =1; / *assigning job 1 to time slot*/ 5. k:=1; 6. For i:=2 to n do 7. { 8. r:=k; 9. while((D[T[r]]>D[i]) and (D[T[r]]!=r))do r:=r-1; 10. if ((D[T[r]]<=D[i]) and (D[i]>r))then 11. { 12. for q:=k to (r+1) step-1 do T[q+1]:=T[q]; /*”step-1” implies making the consecutive slots empty*/ 13. T[r+1]:= i; k:=k+1; 14. } 15. } 16. Return k; 17. }
  • 3. Example: Q. Let n=5;p=(20,15,10,5,1);d=(2,2,1,3,3) Ans:- Given: Jobs J1 J2 J3 J4 J5 Profits 20 15 10 5 1 Deadline 2 2 1 3 3
  • 4. Now , we give index to jobs: n=5 i Index 1 2 3 4 5 Jobs J1 J2 J3 J4 J5 Profits 20 15 10 5 1 Deadline 2 2 1 3 3
  • 5. The maximum deadline given for a job in the egs is: 3. Hence, Dmax=3. So we can get a maximum of 3 time slots(initially-1 job- 1 unit of time). Henceforth , we create a table for time slot ,T: Timeslot 1 2 3 Status
  • 6. From the algo we are solving the problem:  Look at index 1 of job array , its deadline is 2 ,tf it has to come in the first slot. Now, assigning i=1 =>J1 to timeslot array, T[]. Then , assigning other slots to be Empty[-1]. T[1] : =1; / *assigning job 1 to time slot*/ for q:=k to (r+1) step-1 do T[q+1]:=T[q]; /*”step-1” implies making the consecutive slots empty*/ T[r+1]:= i; k:=k+1; Table will be now,
  • 7. Now , i becomes 2 Formula of k is min(Dmax, deadline(i)) k checks which is the min among the values  k =min(3,2)=2; Checking if k>=1. The solution is a yes . Hence, checking timeslot(k)==-1or empty If yes fill it with the corresponding job. Now , i becomes 3 Formula of k is min(Dmax, deadline(i)) k checks which is the min among the values  k =min(3,1)=1; Checking if k>=1. The solution is a yes . Hence, checking timeslot(k)==-1or empty It’s a no,hence decrementing k by 1 and j3 rejected.
  • 8. Now , i becomes 4 Formula of k is min(Dmax, deadline(i)) k checks which is the min among the values  k =min(3,3)=3; Checking if k>=1. The solution is a yes . Hence, checking timeslot(k)==-1or empty If yes fill it with the corresponding job.(j4) Now , i becomes 5 Formula of k is min(Dmax, deadline(i)) k checks which is the min among the values  k =min(3,3)=3; Checking if k>=1. The solution is a yes . Hence, checking timeslot(k)==-1or empty It’s a no, hence decrement k by 1 and reject j5 and exit for loop.
  • 9. Final timeslot table results give a sequece of jobs with max profit which meet the deadlines. Therefore the sequence of jobs is : J1->J2->J4
  • 10. •Algorithm that can be prepared from the example(for easy implementation)
  • 11. 1. Algorithm JS(D,J,n) 2. { 3. D[0] :=J[0] :=0; 4. for i:=1 to n 5. { 6. T[i]=-1; 7. } 8. J[1]:=1; 9. for i:=2 to n 10. { 11. k:= min(Dmax,D(i)); 12. if(k>=1) then 13. { 14. if(T[k]==-1) then 15. { 16. T[k]:=J[k]; 17. } 18. else 19. k--; 20. } 21. }