SLIDE 17 2/8/19 17
Interval Partitioning: Greedy Algorithm
- Consider lectures in increasing order of start
time: assign lecture to any compatible classroom
Feb 8, 2019 CSCI211 - Sprenkle 33
Sort intervals by starting time so that s Sort intervals by starting time so that s1 £ s2 £ ... ... £ sn d = 0 for for j = 1 = 1 to to n if if lecture j is compatible with some classroom k lecture j is compatible with some classroom k schedule lecture schedule lecture j in classroom in classroom k else else allocate a new classroom allocate a new classroom d + 1 + 1 schedule lecture schedule lecture j in classroom in classroom d + 1 + 1 d = = d + 1 + 1 number of allocated classrooms
Analyze algorithm
Sort intervals by starting time so that s Sort intervals by starting time so that s1 £ s2 £ ... ... £ sn d = 0 for for j = 1 = 1 to to n if if (lecture (lecture j is compatible with some classroom is compatible with some classroom k) schedule lecture schedule lecture j in classroom in classroom k else else allocate a new classroom allocate a new classroom d + 1 + 1 schedule lecture schedule lecture j in classroom in classroom d + 1 + 1 d = = d + 1 + 1
Interval Partitioning: Greedy Algorithm
- Consider lectures in increasing order of start time: assign
lecture to any compatible classroom
- Implementation: O(n log n)
Ø For each classroom k, maintain the finish time of the last job added. Ø Keep the classrooms in a priority queue by last job finish time.
Feb 8, 2019 CSCI211 - Sprenkle 34
number of allocated classrooms