Def Greedy Algorithm The greedy algorithm makes locally optimal choices and may lead to a globally optimal solution.
Fact Requirements of Greedy Algorithm
- Optimal Sub-Structure: Optimal solution to the problem is formed by optimal solutions to sub-problems.
- Greedy-Choice Property: A globally optimal solution can be formed from locally optimal solutions.
Fact Generally, greedy algorithms are faster than dynamic programmings.
Prop Any problem that can be solved by greedy can also be solved by dynamic programming.
Activity Selection Problem
Def Activity Selection Problem
Consider a set of activities
Algorithm
- Sort the activities based on the starting points, give
- Sort the activities based on the finish points, give
- Start with an empty set
- While
is not empty: - Find the activity
with the and add it to - Remove any activity in
which overlaps with using and
- Find the activity
- Return
Proof Consider a set of activities
Prop The overall time complexity of the above algorithm is in