This preview shows page 1. Sign up to view the full content.
Unformatted text preview: bstructure and Greedy Choice properties are true, we can prove the correctness of the greedy algorithm by induction. Greedy algorithm picks the job 1 in its solution. By the Greedy Choice property, there is an optimal solution that also contains the job 1. So this selection needs not be reversed. The greedy algorithm delete all jobs that are incompatible with job 1. The remaining jobs is the set S1 in the proof of Optimal Substructure property. By induction hypothesis, Greedy algorithm will output an optimal solution X1 for S1 . c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 36 / 49 Proof of Correctness
Since the Optimal Substructure and Greedy Choice properties are true, we can prove the correctness of the greedy algorithm by induction. Greedy algorithm picks the job 1 in its solution. By the Greedy Choice property, there is an optimal solution that also contains the job 1. So this selection needs not be reversed. The greedy algorithm delete all jobs that are incompatible with job 1. The remaining jobs is the set S1 in the proof of Optimal Substructure property. By induction hypothesis, Greedy algorithm will output an optimal solution X1 for S1 . By the Optimal Substructure property, X = X1 {1} is an optimal solution of the original job set S. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 36 / 49 Proof of Correctness
Since the Optimal Substructure and Greedy Choice properties are true, we can prove the correctness of the greedy algorithm by induction. Greedy algorithm picks the job 1 in its solution. By the Greedy Choice property, there is an optimal solution that also contains the job 1. So this selection needs not be reversed. The greedy algorithm delete all jobs that are incompatible with job 1. The remaining jobs is the set S1 in the proof of Optimal Substructure property. By induction hypothesis, Greedy algorithm will output an optimal solution X1 for S1 . By the Optimal Substructure property, X = X1 {1} is an optimal solution of the original job set S. X is the output from Greedy algorithm. So the algorithm is correct. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 36 / 49 Proof of Correctness
Since the Optimal Substructure and Greedy Choice properties are true, we can prove the correctness of the greedy algorithm by induction. Greedy algorithm picks the job 1 in its solution. By the Greedy Choice property, there is an optimal solution that also contains the job 1. So this selection needs not be reversed. The greedy algorithm delete all jobs that are incompatible with job 1. The remaining jobs is the set S1 in the proof of Optimal Substructure property. By induction hypothesis, Greedy algorithm will output an optimal solution X1 for S1 . By the Optimal Substructure property, X = X1 {1} is an optimal solution of the original job set S. X is the output from Greedy algorithm. So the algorithm is correct. Runtime: Clearly O(n log n) (dominated by sorting).
c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 36 / 49 Outline 1 Greedy Algorithms Elements of Greedy Algorithms Greedy Choice Property for Kruskal's Algorithm 0/1 Knapsack Problem Activity Selection Problem Scheduling All Intervals 2 3 4 5 6 c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 37 / 49 Scheduling All Intervals Schedule all activities using as few resources as possible. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 38 / 49 Scheduling All Intervals Schedule all activities using as few resources as possible. Input: A set R = {I1 , . . . , In } of n requests/activities. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 38 / 49 Scheduling All Intervals Schedule all activities using as few resources as possible. Input: A set R = {I1 , . . . , In } of n requests/activities. Each Ii has a start time si and finish time fi . (So each Ii is represented by an interval [si , fi )). c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 38 / 49 Scheduling All Intervals Schedule all activities using as few resources as possible. Input: A set R = {I1 , . . . , In } of n requests/activities. Each Ii has a start time si and finish time fi . (So each Ii is represented by an interval [si , fi )). Output: A partition of R into as few subsets as possible, so that the intervals in each subset are mutually compatible. (Namely, they do not overlap.) c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 38 / 49 Scheduling All Intervals Application
Each request Ii is a job to be run on a CPU. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 39 / 49 Scheduling All Intervals Application
Each request Ii is a job to be run on a CPU. If two intervals Ip and Iq overlap, they cannot run on the same CPU. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 39 / 49 Scheduling All Intervals Application
Each request Ii is a job to be run on a CPU. If two intervals Ip and Iq overlap, they cannot...
View Full
Document
 Fall '11
 XINHE
 Algorithms

Click to edit the document details