SlideShare a Scribd company logo
•Yastee A. Shah (16it148)
By:
Design and
Analyze
Algorithm
(IT-341)
TOPIC :
FIND MINIMUM TIME TO
FINISH ALL JOBS WITH
GIVEN CONSTRAINTS..!
2
Variables used :
3
Input :
K: Number of assignees available.
T: Time taken by an assignee to
finish one
unit of job
job[]: An array that represents time
requirements
of different jobs.
Constraints:
■ An assignee can be assigned only contiguous jobs.
For example, an assignee cannot be assigned jobs 1
and 3, but not 2.
■ Two assignees cannot share (or co-assigned) a job,
i.e., a job cannot be partially assigned to one
assignee and partially to other.
4
Code:
5
// Driver program
int main()
{
int job[] = {10, 7, 8, 12, 6, 8};
int n = sizeof(job)/sizeof(job[0]);
int k = 4, T = 5;
cout << findMinTime(k, T, job, n) << endl;
return 0;
}
…..(2)
6
// Returns minimum time required to finish given array of jobs
// k --> number of assignees
// T --> Time required by every assignee to finish 1 unit
// n --> Number of jobs
int findMinTime(int K, int T, int job[], int n)
{
// Set start and end for binary search
// end provides an upper limit on time
int end = 0, start = 0;
for (int i = 0; i < n; ++i)
end += job[i];
int ans = end; // Initialize answer
// Find the job that takes maximum time
int job_max = getMax(job, n);
…..(3)
7
// Do binary search for minimum feasible time
while (start <= end)
{
int mid = (start + end) / 2;
// If it is possible to finish jobs in mid time
if (mid >= job_max && isPossible(mid, K, job, n)) {
ans = min(ans, mid); // Update answer
end = mid - 1;
}
else
start = mid + 1;
}
return (ans * T);
}
…..(4)
8
// Utility function to get maximum element in
job[0..n-1]
int getMax(int arr[], int n)
{
int result = arr[0];
for (int i=1; i<n; i++)
if (arr[i] > result)
result = arr[i];
return result;
}
…..(5)
9
// Returns true if it is possible to finish jobs[] within
// given time 'time'
bool isPossible(int time, int K, int job[], int n)
{
// cnt is count of current assignees required for
jobs
int cnt = 1;
int curr_time = 0; // time assigned to current
assignee
…..(6)
10
for (int i = 0; i < n;) {
// If time assigned to current assignee exceeds max,
// increment count of assignees.
if (curr_time + job[i] > time) {
curr_time = 0;
cnt++;
}
else { // Else add time of job to current time and move
// to next job.
curr_time += job[i];
i++;
}
}
// Returns true if count is smaller than k
return (cnt <= K);
}
Example :
11
(1)
Input: k = 2, T = 5, job[] = {4, 5, 10}
Output: 50 The minimum time required to finish all the jobs is
50. There are 2 assignees available. We get this time by
assigning {4, 5} to first assignee and {10} to second
assignee.
(2)
Input: k = 4, T = 5, job[] = {10, 7, 8, 12, 6, 8}
Output: 75 We get this time by assigning {10} {7, 8} {12} and
{6, 8}
Thank you
For Watching..☺
12

More Related Content

Similar to FIND MINIMUM TIME TO FINISH ALL JOBS WITH GIVEN CONSTRAINTS.pptx

Modify the Time classattached to be able to work with Date.pdf
Modify the Time classattached to be able to work with Date.pdfModify the Time classattached to be able to work with Date.pdf
Modify the Time classattached to be able to work with Date.pdf
aaseletronics2013
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
josies1
 
Bicriteria in constrained n x 3 flow shop to minimize the rental cost, setup ...
Bicriteria in constrained n x 3 flow shop to minimize the rental cost, setup ...Bicriteria in constrained n x 3 flow shop to minimize the rental cost, setup ...
Bicriteria in constrained n x 3 flow shop to minimize the rental cost, setup ...
Alexander Decker
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
babuk110
 
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfC++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdf
jaipur2
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functions
TAlha MAlik
 
Please I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfPlease I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdf
ankit11134
 

Similar to FIND MINIMUM TIME TO FINISH ALL JOBS WITH GIVEN CONSTRAINTS.pptx (20)

Clock driven scheduling
Clock driven schedulingClock driven scheduling
Clock driven scheduling
 
Shortest job first scheduling
Shortest job first schedulingShortest job first scheduling
Shortest job first scheduling
 
Process of algorithm evaluation
Process of algorithm evaluationProcess of algorithm evaluation
Process of algorithm evaluation
 
Modify the Time classattached to be able to work with Date.pdf
Modify the Time classattached to be able to work with Date.pdfModify the Time classattached to be able to work with Date.pdf
Modify the Time classattached to be able to work with Date.pdf
 
Using information theory principles to schedule real time tasks
 Using information theory principles to schedule real time tasks Using information theory principles to schedule real time tasks
Using information theory principles to schedule real time tasks
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
 
A Heterogeneous Static Hierarchical Expected Completion Time Based Scheduling...
A Heterogeneous Static Hierarchical Expected Completion Time Based Scheduling...A Heterogeneous Static Hierarchical Expected Completion Time Based Scheduling...
A Heterogeneous Static Hierarchical Expected Completion Time Based Scheduling...
 
Bicriteria in constrained n x 3 flow shop to minimize the rental cost, setup ...
Bicriteria in constrained n x 3 flow shop to minimize the rental cost, setup ...Bicriteria in constrained n x 3 flow shop to minimize the rental cost, setup ...
Bicriteria in constrained n x 3 flow shop to minimize the rental cost, setup ...
 
11.bicriteria in constrained n x 0003www.iiste.org call for paper flow shop t...
11.bicriteria in constrained n x 0003www.iiste.org call for paper flow shop t...11.bicriteria in constrained n x 0003www.iiste.org call for paper flow shop t...
11.bicriteria in constrained n x 0003www.iiste.org call for paper flow shop t...
 
Cpm module iii reference
Cpm module iii referenceCpm module iii reference
Cpm module iii reference
 
Cpm pert
Cpm pertCpm pert
Cpm pert
 
Project management
Project managementProject management
Project management
 
Earliest Due Date Algorithm for Task scheduling for cloud computing
Earliest Due Date  Algorithm for Task scheduling for cloud computingEarliest Due Date  Algorithm for Task scheduling for cloud computing
Earliest Due Date Algorithm for Task scheduling for cloud computing
 
Segment tree
Segment treeSegment tree
Segment tree
 
Operating System Lab Manual
Operating System Lab ManualOperating System Lab Manual
Operating System Lab Manual
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
 
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfC++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdf
 
05_Performance Optimization.pdf
05_Performance Optimization.pdf05_Performance Optimization.pdf
05_Performance Optimization.pdf
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functions
 
Please I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfPlease I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdf
 

More from Yastee Shah

More from Yastee Shah (11)

AWT.pptx
AWT.pptxAWT.pptx
AWT.pptx
 
jdbc vs hibernate.pptx
jdbc vs hibernate.pptxjdbc vs hibernate.pptx
jdbc vs hibernate.pptx
 
Application of Queue.pptx
Application of Queue.pptxApplication of Queue.pptx
Application of Queue.pptx
 
Edison's work habits and thinking about failure.pptx
Edison's work habits and thinking about failure.pptxEdison's work habits and thinking about failure.pptx
Edison's work habits and thinking about failure.pptx
 
Smart grid.pptx
Smart grid.pptxSmart grid.pptx
Smart grid.pptx
 
Html vs xhtml
Html vs xhtmlHtml vs xhtml
Html vs xhtml
 
Raid
RaidRaid
Raid
 
Water Level Indicator
Water Level IndicatorWater Level Indicator
Water Level Indicator
 
Types of virus and saviour
Types of virus and saviourTypes of virus and saviour
Types of virus and saviour
 
Output devices
Output devicesOutput devices
Output devices
 
Math
MathMath
Math
 

Recently uploaded

The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
parmarsneha2
 

Recently uploaded (20)

NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 

FIND MINIMUM TIME TO FINISH ALL JOBS WITH GIVEN CONSTRAINTS.pptx

  • 1. •Yastee A. Shah (16it148) By: Design and Analyze Algorithm (IT-341)
  • 2. TOPIC : FIND MINIMUM TIME TO FINISH ALL JOBS WITH GIVEN CONSTRAINTS..! 2
  • 3. Variables used : 3 Input : K: Number of assignees available. T: Time taken by an assignee to finish one unit of job job[]: An array that represents time requirements of different jobs.
  • 4. Constraints: ■ An assignee can be assigned only contiguous jobs. For example, an assignee cannot be assigned jobs 1 and 3, but not 2. ■ Two assignees cannot share (or co-assigned) a job, i.e., a job cannot be partially assigned to one assignee and partially to other. 4
  • 5. Code: 5 // Driver program int main() { int job[] = {10, 7, 8, 12, 6, 8}; int n = sizeof(job)/sizeof(job[0]); int k = 4, T = 5; cout << findMinTime(k, T, job, n) << endl; return 0; }
  • 6. …..(2) 6 // Returns minimum time required to finish given array of jobs // k --> number of assignees // T --> Time required by every assignee to finish 1 unit // n --> Number of jobs int findMinTime(int K, int T, int job[], int n) { // Set start and end for binary search // end provides an upper limit on time int end = 0, start = 0; for (int i = 0; i < n; ++i) end += job[i]; int ans = end; // Initialize answer // Find the job that takes maximum time int job_max = getMax(job, n);
  • 7. …..(3) 7 // Do binary search for minimum feasible time while (start <= end) { int mid = (start + end) / 2; // If it is possible to finish jobs in mid time if (mid >= job_max && isPossible(mid, K, job, n)) { ans = min(ans, mid); // Update answer end = mid - 1; } else start = mid + 1; } return (ans * T); }
  • 8. …..(4) 8 // Utility function to get maximum element in job[0..n-1] int getMax(int arr[], int n) { int result = arr[0]; for (int i=1; i<n; i++) if (arr[i] > result) result = arr[i]; return result; }
  • 9. …..(5) 9 // Returns true if it is possible to finish jobs[] within // given time 'time' bool isPossible(int time, int K, int job[], int n) { // cnt is count of current assignees required for jobs int cnt = 1; int curr_time = 0; // time assigned to current assignee
  • 10. …..(6) 10 for (int i = 0; i < n;) { // If time assigned to current assignee exceeds max, // increment count of assignees. if (curr_time + job[i] > time) { curr_time = 0; cnt++; } else { // Else add time of job to current time and move // to next job. curr_time += job[i]; i++; } } // Returns true if count is smaller than k return (cnt <= K); }
  • 11. Example : 11 (1) Input: k = 2, T = 5, job[] = {4, 5, 10} Output: 50 The minimum time required to finish all the jobs is 50. There are 2 assignees available. We get this time by assigning {4, 5} to first assignee and {10} to second assignee. (2) Input: k = 4, T = 5, job[] = {10, 7, 8, 12, 6, 8} Output: 75 We get this time by assigning {10} {7, 8} {12} and {6, 8}