Lecture 7
Lecture 7
Greedy Algorithms II
Shang-Hua Teng
Greedy algorithms
• A greedy algorithm always makes the choice that
looks best at the moment
– My everyday examples:
• Driving in Los Angeles, NY, or Boston for that matter
• Playing cards
• Invest on stocks
• Choose a university
– The hope: a locally optimal choice will lead to a globally
optimal solution
– For some problems, it works
• greedy algorithms tend to be easier to code
An Activity Selection Problem
(Conference Scheduling Problem)
• Input: A set of activities S = {a1,…, an}
• Each activity has start time and a finish time
– ai=(si, fi)
• Two activities are compatible if and only if
their interval does not overlap
• Output: a maximum-size subset of
mutually compatible activities
The Activity Selection Problem
• Here are a set of start and finish times