# We discuss a greedy algorithm for solving this

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: empty queue; put [bp , fp ) into this new queue. 6 output k and Q1 , . . . , Qk c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 46 / 49 Scheduling All Intervals I1 I4 I7 I5 I2 I6 I8 I3 After Sorting Q1 Q2 Q3 c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 47 / 49 Scheduling All Intervals Proof of correctness: We only put intervals into available queues. So each queue contains only non-overlapping intervals. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 48 / 49 Scheduling All Intervals Proof of correctness: We only put intervals into available queues. So each queue contains only non-overlapping intervals. We need to show the algorithm uses minimum number of queues. (Namely, partition intervals into minimum number of subsets.) If the input contains k mutually overlapping intervals, we must use at least k queues. (Because no two such intervals can be placed into the same queue.) c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 48 / 49 Scheduling All Intervals Proof of correctness: We only put intervals into available queues. So each queue contains only non-overlapping intervals. We need to show the algorithm uses minimum number of queues. (Namely, partition intervals into minimum number of subsets.) If the input contains k mutually overlapping intervals, we must use at least k queues. (Because no two such intervals can be placed into the same queue.) When the algorithm opens a new empty queue Qk for an interval [bp , fp ), none of the current queues Q1 , , Qk-1 is available. This means that the last intervals in Q1 , , Qk-1 all overlap with [bp , fp ). Hence the input contains k mutually overlapping intervals. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 48 / 49 Scheduling All Intervals Proof of correctness: We only put intervals into available queues. So each queue contains only non-overlapping intervals. We need to show the algorithm uses minimum number of queues. (Namely, partition intervals into minimum number of subsets.) If the input contains k mutually overlapping intervals, we must use at least k queues. (Because no two such intervals can be placed into the same queue.) When the algorithm opens a new empty queue Qk for an interval [bp , fp ), none of the current queues Q1 , , Qk-1 is available. This means that the last intervals in Q1 , , Qk-1 all overlap with [bp , fp ). Hence the input contains k mutually overlapping intervals. The algorithm uses k queues. By the observation above, this is the smallest possible. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 48 / 49 Scheduling All Intervals Runtime Analysis: Sorting takes O(n log n) time. The loop runs n times. The loop body scans Q1 , . . . , Qk to find the first available queue. So it takes O(k) time. Hence, the runtime is (nk), (where k is the number of queues needed, or equivalently the chromatic number (G) of the input interval graph G.) c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 49 / 49 Scheduling All Intervals Runtime Analysis: Sorting takes O(n log n) time. The loop runs n times. The loop body scans Q1 , . . . , Qk to find the first available queue. So it takes O(k) time. Hence, the runtime is (nk), (where k is the number of queues needed, or equivalently the chromatic number (G) of the input interval graph G.) In the worst case, k can be (n). Hence, the worst case runtime is (n2 ). c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 49 / 49...
View Full Document

## This note was uploaded on 02/27/2012 for the course CSE 431/531 taught by Professor Xinhe during the Fall '11 term at SUNY Buffalo.

Ask a homework question - tutors are online