SlideShare a Scribd company logo
1 of 17
“Job
Sequencing
With
Deadlines”
.............a Greedy Algorithm
Define-
The sequencing of jobs on a single processor
with deadline constraints is called as Job
Sequencing with Deadlines.
Here-
• You are given a set of jobs.
• Each job has a defined deadline and some
profit associated with it.
• The profit of a job is given only when that
job is completed within its deadline.
Assumptions-
• Only one processor is available for processing
all the jobs.
• Processor takes one unit of time to complete
a job.
• Non-preemption is there.
The problem states-
“How can the total profit be maximized if only
one job can be completed at a time?”
Approach to Solution-
• A feasible solution would be where each
job in the subset gets completed within its
deadline.
• Value of the feasible solution would be the
sum of profit of all the jobs contained in the
subset.
• An optimal solution of the problem would
be a feasible solution which gives the
maximum profit.
Greedy Algorithm-
Greedy Algorithm is adopted to determine
how the next job is selected for an optimal
solution.
The greedy algorithm described in the next
slide always gives an optimal solution to the
job sequencing problem.
Steps to solve-
Step-01:
•Sort all the given jobs in decreasing order of
their profit.
Step-02:
•Check the value of maximum deadline.
•Draw a Gantt chart where maximum time on
Gantt chart is the value of maximum deadline.
Step-03:
•Pick up the jobs one by one.
•Put the job on Gantt chart as far as possible
from 0 ensuring that the job gets completed
before its deadline.
Jobs J1 J2 J3 J4 J5 J6
Deadlines 5 3 3 2 4 2
Profits 200 180 190 300 120 100
Example Problem-
Given the jobs, their deadlines and associated
profits as shown, answer the following
questions-
•Write the optimal schedule that gives
maximum profit.
•What is the maximum earned profit?
Jobs J4 J1 J3 J2 J5 J6
Deadlines 2 5 3 3 4 2
Profits 300 200 190 180 120 100
Solution-
Step1: Sort all the given jobs in decreasing order
of their profit-
Step2:
Value of maximum deadline = 5.
So, draw a Gantt chart with maximum time on Gantt
chart = 5 units as shown-
Now,
• We take each job one by one in
the order they appear in Step1.
• We place the job on Gantt chart
as far as possible from 0.
Step3:
•We take job J4.
•Since its deadline is 2, so we place it in
the first empty cell before deadline 2
as-
Step4:
•We take job J1.
•Since its deadline is 5, so we place it in the first
empty cell before deadline 5 as-
Step5:
•We take job J3.
•Since its deadline is 3, so we place it in the
first empty cell before deadline 3 as-
Step6:
•We take job J2.
•Since its deadline is 3, so we place it in the first
empty cell before deadline 3.
•Since the second and third cells are already
filled, so we place job J2 in the first cell as-
Step7:
•Now, we take job J5.
•Since its deadline is 4, so we place it in
the first empty cell before deadline 4 as-
Now,
• The only job left is job J6 whose deadline
is 2.
• All the slots before deadline 2 are
already occupied.
• Thus, job J6 can not be completed.
The optimal schedule is-
J2 , J4 , J3 , J5 , J1
This is the required order in which the jobs must
be completed in order to obtain the maximum
profit.
Maximum earned profit
= Sum of profit of all the jobs in optimal schedule
= Profit of job J2 + Profit of job J4 + Profit of job
J3 + Profit of job J5 + Profit of job J1
= 180 + 300 + 190 + 120 + 200
= 990 units
Time Complexity Analysis:
Time for sorting on basis of profits = O (n log n)
Next, two loops are used one within
the other, for which complexity = O (n^2)
Hence, the overall complexity of this algorithm
becomes O(n^2).
Program-
#include<iostream>
#include<algorithm>
using namespace std;
struct Job //stores details of each job
{ char id;
int dead;
int profit; };
bool comparison(Job a, Job b) //used in sorting acc. to profits
{ return (a.profit > b.profit); }
void printJobScheduling(Job arr[], int n)
{
sort(arr, arr+n, comparison);
int result[n];
bool slot[n];
for (int i=0; i<n; i++)
slot[i] = false;
for (int i=0; i<n; i++)
{ for (int j=min(n, arr[i].dead)-1; j>=0; j--)
{ if (slot[j]==false)
{ result[j] = i;
slot[j] = true;
break;
} } }
for (int i=0; i<n; i++)
if (slot[i])
cout << arr[result[i]].id << " ";
}
int main()
{
Job arr[] = { {'a', 5, 200}, {'b', 3, 180}, {'c', 3, 190}, {'d', 2, 300},
{'e', 4, 120}, {‘f’, 2, 100} };
int n = sizeof(arr)/sizeof(arr[0]);
cout << "Following is maximum profit sequence of jobs n";
printJobScheduling(arr, n);
return 0;
}
Maximize Profits by Sequencing Jobs with Deadlines

More Related Content

What's hot

daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy methodhodcsencet
 
Travelling Salesman
Travelling SalesmanTravelling Salesman
Travelling SalesmanShuvojit Kar
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardAnimesh Chaturvedi
 
Assignment problem branch and bound.pptx
Assignment problem branch and bound.pptxAssignment problem branch and bound.pptx
Assignment problem branch and bound.pptxKrishnaVardhan50
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemMadhu Bala
 
Job sequencing in Data Strcture
Job sequencing in Data StrctureJob sequencing in Data Strcture
Job sequencing in Data StrctureRabin BK
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.MOHIT DADU
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating systemAli Haider
 
Travelling salesman dynamic programming
Travelling salesman dynamic programmingTravelling salesman dynamic programming
Travelling salesman dynamic programmingmaharajdey
 
All pair shortest path
All pair shortest pathAll pair shortest path
All pair shortest pathArafat Hossan
 
Merge sort analysis and its real time applications
Merge sort analysis and its real time applicationsMerge sort analysis and its real time applications
Merge sort analysis and its real time applicationsyazad dumasia
 
Traveling salesman problem
Traveling salesman problemTraveling salesman problem
Traveling salesman problemJayesh Chauhan
 

What's hot (20)

daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Travelling Salesman
Travelling SalesmanTravelling Salesman
Travelling Salesman
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
 
Assignment problem branch and bound.pptx
Assignment problem branch and bound.pptxAssignment problem branch and bound.pptx
Assignment problem branch and bound.pptx
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
Merge sort algorithm power point presentation
Merge sort algorithm power point presentationMerge sort algorithm power point presentation
Merge sort algorithm power point presentation
 
Job sequencing in Data Strcture
Job sequencing in Data StrctureJob sequencing in Data Strcture
Job sequencing in Data Strcture
 
Np cooks theorem
Np cooks theoremNp cooks theorem
Np cooks theorem
 
Semaphores
SemaphoresSemaphores
Semaphores
 
Quick sort
Quick sortQuick sort
Quick sort
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating system
 
Travelling salesman dynamic programming
Travelling salesman dynamic programmingTravelling salesman dynamic programming
Travelling salesman dynamic programming
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Heap sort
Heap sortHeap sort
Heap sort
 
All pair shortest path
All pair shortest pathAll pair shortest path
All pair shortest path
 
Merge sort analysis and its real time applications
Merge sort analysis and its real time applicationsMerge sort analysis and its real time applications
Merge sort analysis and its real time applications
 
Traveling salesman problem
Traveling salesman problemTraveling salesman problem
Traveling salesman problem
 

Similar to Maximize Profits by Sequencing Jobs with Deadlines

data structures and algorithms Unit 4
data structures and algorithms Unit 4data structures and algorithms Unit 4
data structures and algorithms Unit 4infanciaj
 
Job shop scheduling
Job shop schedulingJob shop scheduling
Job shop schedulingSujeet TAMBE
 
Job Shop Scheduling.pptx
Job Shop Scheduling.pptxJob Shop Scheduling.pptx
Job Shop Scheduling.pptxSyedAmirIqbal3
 
Computational Thinking 11- ActivitySelection.pptx
Computational Thinking 11- ActivitySelection.pptxComputational Thinking 11- ActivitySelection.pptx
Computational Thinking 11- ActivitySelection.pptxssuser1a5f25
 
Clock driven scheduling
Clock driven schedulingClock driven scheduling
Clock driven schedulingKamal Acharya
 
Approximation Algorithms Part Two: More Constant factor approximations
Approximation Algorithms Part Two: More Constant factor approximationsApproximation Algorithms Part Two: More Constant factor approximations
Approximation Algorithms Part Two: More Constant factor approximationsBenjamin Sach
 
Operations Research_18ME735_module 5 sequencing notes.pdf
Operations Research_18ME735_module 5 sequencing notes.pdfOperations Research_18ME735_module 5 sequencing notes.pdf
Operations Research_18ME735_module 5 sequencing notes.pdfRoopaDNDandally
 
Chapter One.pdf
Chapter One.pdfChapter One.pdf
Chapter One.pdfabay golla
 
SCHEDULING RULES DONE.pptx
SCHEDULING  RULES DONE.pptxSCHEDULING  RULES DONE.pptx
SCHEDULING RULES DONE.pptxAgnibhaBanerjee1
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithmsiqbalphy1
 
Sequential Models - Meaning, assumptions, Types and Problems
Sequential Models - Meaning, assumptions, Types and ProblemsSequential Models - Meaning, assumptions, Types and Problems
Sequential Models - Meaning, assumptions, Types and ProblemsSundar B N
 
Application of branch and bound technique for nx3 flow shop scheduling, in wh...
Application of branch and bound technique for nx3 flow shop scheduling, in wh...Application of branch and bound technique for nx3 flow shop scheduling, in wh...
Application of branch and bound technique for nx3 flow shop scheduling, in wh...Alexander Decker
 
Approaches to real time scheduling
Approaches to real time schedulingApproaches to real time scheduling
Approaches to real time schedulingKamal Acharya
 

Similar to Maximize Profits by Sequencing Jobs with Deadlines (20)

data structures and algorithms Unit 4
data structures and algorithms Unit 4data structures and algorithms Unit 4
data structures and algorithms Unit 4
 
deadline.pptx
deadline.pptxdeadline.pptx
deadline.pptx
 
Flowshop scheduling
Flowshop schedulingFlowshop scheduling
Flowshop scheduling
 
Greedy method
Greedy methodGreedy method
Greedy method
 
Job shop scheduling
Job shop schedulingJob shop scheduling
Job shop scheduling
 
Job Shop Scheduling.pptx
Job Shop Scheduling.pptxJob Shop Scheduling.pptx
Job Shop Scheduling.pptx
 
Computational Thinking 11- ActivitySelection.pptx
Computational Thinking 11- ActivitySelection.pptxComputational Thinking 11- ActivitySelection.pptx
Computational Thinking 11- ActivitySelection.pptx
 
Clock driven scheduling
Clock driven schedulingClock driven scheduling
Clock driven scheduling
 
Approximation Algorithms Part Two: More Constant factor approximations
Approximation Algorithms Part Two: More Constant factor approximationsApproximation Algorithms Part Two: More Constant factor approximations
Approximation Algorithms Part Two: More Constant factor approximations
 
9Johnson's Rule.ppt
9Johnson's Rule.ppt9Johnson's Rule.ppt
9Johnson's Rule.ppt
 
Operations Research_18ME735_module 5 sequencing notes.pdf
Operations Research_18ME735_module 5 sequencing notes.pdfOperations Research_18ME735_module 5 sequencing notes.pdf
Operations Research_18ME735_module 5 sequencing notes.pdf
 
Chapter One.pdf
Chapter One.pdfChapter One.pdf
Chapter One.pdf
 
Module 3_DAA (2).pptx
Module 3_DAA (2).pptxModule 3_DAA (2).pptx
Module 3_DAA (2).pptx
 
SCHEDULING RULES DONE.pptx
SCHEDULING  RULES DONE.pptxSCHEDULING  RULES DONE.pptx
SCHEDULING RULES DONE.pptx
 
Cpm pert
Cpm pertCpm pert
Cpm pert
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Sequential Models - Meaning, assumptions, Types and Problems
Sequential Models - Meaning, assumptions, Types and ProblemsSequential Models - Meaning, assumptions, Types and Problems
Sequential Models - Meaning, assumptions, Types and Problems
 
Application of branch and bound technique for nx3 flow shop scheduling, in wh...
Application of branch and bound technique for nx3 flow shop scheduling, in wh...Application of branch and bound technique for nx3 flow shop scheduling, in wh...
Application of branch and bound technique for nx3 flow shop scheduling, in wh...
 
Approaches to real time scheduling
Approaches to real time schedulingApproaches to real time scheduling
Approaches to real time scheduling
 
Lecture1
Lecture1Lecture1
Lecture1
 

Recently uploaded

MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
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
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
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
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
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
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
(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
 
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
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
(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
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 

Recently uploaded (20)

MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
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
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
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
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
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
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
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
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
(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
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
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
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
(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...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 

Maximize Profits by Sequencing Jobs with Deadlines

  • 2. Define- The sequencing of jobs on a single processor with deadline constraints is called as Job Sequencing with Deadlines. Here- • You are given a set of jobs. • Each job has a defined deadline and some profit associated with it. • The profit of a job is given only when that job is completed within its deadline.
  • 3. Assumptions- • Only one processor is available for processing all the jobs. • Processor takes one unit of time to complete a job. • Non-preemption is there. The problem states- “How can the total profit be maximized if only one job can be completed at a time?”
  • 4. Approach to Solution- • A feasible solution would be where each job in the subset gets completed within its deadline. • Value of the feasible solution would be the sum of profit of all the jobs contained in the subset. • An optimal solution of the problem would be a feasible solution which gives the maximum profit.
  • 5. Greedy Algorithm- Greedy Algorithm is adopted to determine how the next job is selected for an optimal solution. The greedy algorithm described in the next slide always gives an optimal solution to the job sequencing problem.
  • 6. Steps to solve- Step-01: •Sort all the given jobs in decreasing order of their profit. Step-02: •Check the value of maximum deadline. •Draw a Gantt chart where maximum time on Gantt chart is the value of maximum deadline. Step-03: •Pick up the jobs one by one. •Put the job on Gantt chart as far as possible from 0 ensuring that the job gets completed before its deadline.
  • 7. Jobs J1 J2 J3 J4 J5 J6 Deadlines 5 3 3 2 4 2 Profits 200 180 190 300 120 100 Example Problem- Given the jobs, their deadlines and associated profits as shown, answer the following questions- •Write the optimal schedule that gives maximum profit. •What is the maximum earned profit?
  • 8. Jobs J4 J1 J3 J2 J5 J6 Deadlines 2 5 3 3 4 2 Profits 300 200 190 180 120 100 Solution- Step1: Sort all the given jobs in decreasing order of their profit-
  • 9. Step2: Value of maximum deadline = 5. So, draw a Gantt chart with maximum time on Gantt chart = 5 units as shown- Now, • We take each job one by one in the order they appear in Step1. • We place the job on Gantt chart as far as possible from 0.
  • 10. Step3: •We take job J4. •Since its deadline is 2, so we place it in the first empty cell before deadline 2 as- Step4: •We take job J1. •Since its deadline is 5, so we place it in the first empty cell before deadline 5 as-
  • 11. Step5: •We take job J3. •Since its deadline is 3, so we place it in the first empty cell before deadline 3 as- Step6: •We take job J2. •Since its deadline is 3, so we place it in the first empty cell before deadline 3. •Since the second and third cells are already filled, so we place job J2 in the first cell as-
  • 12. Step7: •Now, we take job J5. •Since its deadline is 4, so we place it in the first empty cell before deadline 4 as- Now, • The only job left is job J6 whose deadline is 2. • All the slots before deadline 2 are already occupied. • Thus, job J6 can not be completed.
  • 13. The optimal schedule is- J2 , J4 , J3 , J5 , J1 This is the required order in which the jobs must be completed in order to obtain the maximum profit. Maximum earned profit = Sum of profit of all the jobs in optimal schedule = Profit of job J2 + Profit of job J4 + Profit of job J3 + Profit of job J5 + Profit of job J1 = 180 + 300 + 190 + 120 + 200 = 990 units
  • 14. Time Complexity Analysis: Time for sorting on basis of profits = O (n log n) Next, two loops are used one within the other, for which complexity = O (n^2) Hence, the overall complexity of this algorithm becomes O(n^2).
  • 15. Program- #include<iostream> #include<algorithm> using namespace std; struct Job //stores details of each job { char id; int dead; int profit; }; bool comparison(Job a, Job b) //used in sorting acc. to profits { return (a.profit > b.profit); } void printJobScheduling(Job arr[], int n) { sort(arr, arr+n, comparison); int result[n]; bool slot[n]; for (int i=0; i<n; i++) slot[i] = false;
  • 16. for (int i=0; i<n; i++) { for (int j=min(n, arr[i].dead)-1; j>=0; j--) { if (slot[j]==false) { result[j] = i; slot[j] = true; break; } } } for (int i=0; i<n; i++) if (slot[i]) cout << arr[result[i]].id << " "; } int main() { Job arr[] = { {'a', 5, 200}, {'b', 3, 180}, {'c', 3, 190}, {'d', 2, 300}, {'e', 4, 120}, {‘f’, 2, 100} }; int n = sizeof(arr)/sizeof(arr[0]); cout << "Following is maximum profit sequence of jobs n"; printJobScheduling(arr, n); return 0; }