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

PPT
friends functionToshu
PPTX
Lecture 4 - Engineering project Scheduling.pptx
PPT
Overloading
PPTX
SCHEDULING RULES DONE.pptx
PPTX
Algorithm analysis
DOCX
Lab 1 izz
PPTX
Design and analysis of algorithms
PDF
Operations Research_18ME735_module 5 sequencing notes.pdf
friends functionToshu
Lecture 4 - Engineering project Scheduling.pptx
Overloading
SCHEDULING RULES DONE.pptx
Algorithm analysis
Lab 1 izz
Design and analysis of algorithms
Operations Research_18ME735_module 5 sequencing notes.pdf

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

PPTX
Clock driven scheduling
PDF
Shortest job first scheduling
PPTX
Process of algorithm evaluation
PPTX
Analysis of Algorithms (CSE II/III year)
PDF
Modify the Time classattached to be able to work with Date.pdf
PPTX
Using information theory principles to schedule real time tasks
DOCX
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
PDF
A Heterogeneous Static Hierarchical Expected Completion Time Based Scheduling...
PPTX
Lecture 2 DataStrucure - complexity , IS.pptx
PDF
introduction to python programming course 2
PDF
11.bicriteria in constrained n x 0003www.iiste.org call for paper flow shop t...
PDF
Bicriteria in constrained n x 3 flow shop to minimize the rental cost, setup ...
PDF
Cpm module iii reference
PPTX
Cpm pert
PPT
Project management
PPTX
Earliest Due Date Algorithm for Task scheduling for cloud computing
PPT
Segment tree
PDF
Operating System Lab Manual
PPTX
Sequencing and shedulding problems for Operations management
PDF
Data Structure & Algorithms - Mathematical
Clock driven scheduling
Shortest job first scheduling
Process of algorithm evaluation
Analysis of Algorithms (CSE II/III year)
Modify the Time classattached to be able to work with Date.pdf
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
A Heterogeneous Static Hierarchical Expected Completion Time Based Scheduling...
Lecture 2 DataStrucure - complexity , IS.pptx
introduction to python programming course 2
11.bicriteria in constrained n x 0003www.iiste.org call for paper flow shop t...
Bicriteria in constrained n x 3 flow shop to minimize the rental cost, setup ...
Cpm module iii reference
Cpm pert
Project management
Earliest Due Date Algorithm for Task scheduling for cloud computing
Segment tree
Operating System Lab Manual
Sequencing and shedulding problems for Operations management
Data Structure & Algorithms - Mathematical
Ad

More from Yastee Shah (11)

PPTX
AWT.pptx
PPTX
jdbc vs hibernate.pptx
PPTX
Application of Queue.pptx
PPTX
Edison's work habits and thinking about failure.pptx
PPTX
Smart grid.pptx
PPTX
Html vs xhtml
PPTX
PPTX
Water Level Indicator
PPTX
Types of virus and saviour
PPTX
Output devices
PPTX
AWT.pptx
jdbc vs hibernate.pptx
Application of Queue.pptx
Edison's work habits and thinking about failure.pptx
Smart grid.pptx
Html vs xhtml
Water Level Indicator
Types of virus and saviour
Output devices
Ad

Recently uploaded (20)

PDF
Classroom Observation Tools for Teachers
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Complications of Minimal Access Surgery at WLH
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Computing-Curriculum for Schools in Ghana
PDF
01-Introduction-to-Information-Management.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Institutional Correction lecture only . . .
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Pre independence Education in Inndia.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Lesson notes of climatology university.
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
Classroom Observation Tools for Teachers
STATICS OF THE RIGID BODIES Hibbelers.pdf
RMMM.pdf make it easy to upload and study
Complications of Minimal Access Surgery at WLH
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Computing-Curriculum for Schools in Ghana
01-Introduction-to-Information-Management.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Anesthesia in Laparoscopic Surgery in India
Institutional Correction lecture only . . .
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
O7-L3 Supply Chain Operations - ICLT Program
Abdominal Access Techniques with Prof. Dr. R K Mishra
Pre independence Education in Inndia.pdf
Final Presentation General Medicine 03-08-2024.pptx
Lesson notes of climatology university.
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Supply Chain Operations Speaking Notes -ICLT Program
Microbial diseases, their pathogenesis and prophylaxis
102 student loan defaulters named and shamed – Is someone you know on the list?

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}