0% found this document useful (0 votes)
84 views11 pages

S13 Interval Scheduling

This document summarizes an algorithm for the interval scheduling problem. It describes the problem as taking a set of jobs, where each job j starts at time sj and finishes at time fj. The goal is to find the maximum subset of jobs that do not overlap. It presents the greedy algorithm of considering jobs in order of earliest finish time fj. It proves that this greedy algorithm is optimal by showing that if a non-greedy job is replaced by a greedy one, the solution remains feasible.

Uploaded by

Z Goo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views11 pages

S13 Interval Scheduling

This document summarizes an algorithm for the interval scheduling problem. It describes the problem as taking a set of jobs, where each job j starts at time sj and finishes at time fj. The goal is to find the maximum subset of jobs that do not overlap. It presents the greedy algorithm of considering jobs in order of earliest finish time fj. It proves that this greedy algorithm is optimal by showing that if a non-greedy job is replaced by a greedy one, the solution remains feasible.

Uploaded by

Z Goo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

COMP3251


Lecture 13: Interval Scheduling


Example: Basic Job Scheduling
Input: A set of n jobs (homework assignments), 

where each job j is associated with a size sj and a deadline dj.

Output: An assignment of jobs to time slots such that:

1) each job gets a number of time slots that equals its size;

2) each job is completed before its corresponding deadline.

Example:
jobs 1 2 3 4 5
size 1 2 1 2 2
deadline 2 4 5 8 9

time 1 2 3 4 5 6 7 8 9 10
job assignment 1 - 2 2 3 4 4 - 5 -

COMP3251 2 Zhiyi Huang


Greed is good!
A greedy algorithm for job scheduling: 

Finish the job (homework assignment) with the closest deadline,
and then the job with the second closest deadline, and so on.


Claim. If the greedy algorithm fails to nd a feasible schedule,


then the input jobs do not admit a feasible schedule.

Proof. (Assume for simplicity that d1 < d2 < … < dn.)

- The rst s1 time slots are assigned to job 1, the next s2 time
slots are assigned to job 2, and so on.

- Let j be a job that is not completed by its deadline.

- That means, s1 + s2 + … + sj > dj, namely, the amount of work


that has to be done from time 1 to time dj is more than dj!

COMP3251 3 Zhiyi Huang


fi
fi
Interval Scheduling Problem
• A set of n jobs, where job j starts at sj and nishes at fj.

• Two jobs are compatible if they don’t overlap.

• Goal: Find maximum subset of mutually compatible jobs

• Example:

job 1
job 2
job 3
job 4
job 5
job 6
job 7

COMP3251 4 Zhiyi Huang


fi
Interval Scheduling Problem
• A set of n jobs, where job j starts at sj and nishes at fj.

• Two jobs are compatible if they don’t overlap.

• Goal: Find maximum subset of mutually compatible jobs

• Example:

job 1
job 2
job 3
job 4
job 5
job 6
job 7

COMP3251 5 Zhiyi Huang


fi
Greedy Algorithms for Interval Scheduling

Greedy template: Consider jobs in some order. Take each job


provided it’s compatible with the ones already taken.

- [Earliest start time] 



Consider jobs in ascending order of start time sj.

- [Earliest nish time] 



Consider jobs in ascending order of nish time fj.

- [Shortest interval] 

Consider jobs in ascending order of interval length fj - sj.

- [Fewest con icts] 



For each job, count the number of con icting jobs cj.
Schedule in ascending order of con icts cj.

COMP3251 6 Zhiyi Huang


fi
fl
fl
fi
fl
Counter Examples for 

Some Greedy Algorithms
• [Earliest start time]:


• [Shortest interval]


• [Fewest con icts]

COMP3251 7 Zhiyi Huang


fl
Earliest Finish Time
Greedy algorithm: Consider jobs in increasing order of nish
time. Take each job provided it's compatible with the ones
already taken.







Running time: O(n log n).

- Remember job j* that was added last to A.

- Job j is compatible with A if sj ≥ fj*.

COMP3251 8 Zhiyi Huang


fi
Greed is good!
Theorem. The greedy algorithm is optimal.

Proof.
- Assume greedy is not optimal, and let’s see what happens.

- Let i1, i2, ... , ik denote the set of jobs selected by greedy.

- Let j1, j2, ... , jm denote the set of jobs in the optimal solution
with i1 = j1, i2 = j2, … , ir = jr for the largest possible value of r.

i1 i2 … ir ir+1
Greedy

j1 j2 … jr jr+1
Optimal

ir+1 nishes before jr+1 by de nition of the greedy algorithm.


COMP3251 9 Zhiyi Huang
fi
fi
Greed is good!
Theorem. The greedy algorithm is optimal.

Proof.
- Assume greedy is not optimal, and let’s see what happens.

- Let i1, i2, ... , ik denote the set of jobs selected by greedy.

- Let j1, j2, ... , jm denote the set of jobs in the optimal solution
with i1 = j1, i2 = j2, … , ir = jr for the largest possible value of r.

i1 i2 … ir ir+1
Greedy

j1 j2 … jr ir+1jr+1
Optimal

The optimal remains feasible if we replace jr+1 with ir+1.


COMP3251 10 Zhiyi Huang
Greed is good!
Theorem. The greedy algorithm is optimal.

Proof.
- Assume greedy is not optimal, and let’s see what happens.

- Let i1, i2, ... , ik denote the set of jobs selected by greedy.

- Let j1, j2, ... , jm denote the set of jobs in the optimal solution
with i1 = j1, i2 = j2, … , ir = jr for the largest possible value of r.

i1 i2 … ir ir+1
Greedy

j1 j2 … jr ir+1jr+1
Optimal

Repeating this process shows the optimality of greedy.


COMP3251 11 Zhiyi Huang

You might also like