Lecture 5 Greedy Algorithm
Lecture 5 Greedy Algorithm
Dynamic Programming
Greedy Algorithm
Optimal Solutions
Dynamic Programming
Algorithms for optimization problems typically go through a
sequence of steps, with a set of choices at each step. For many
optimization problems, using dynamic programming to determine
the best choices is overkill; simpler, more efficient algorithms will
do.
Greedy Algorithm:
A greedy algorithm always makes the choice that looks best at
the moment. That is, it makes a locally optimal choice in the hope
that this choice will lead to a globally optimal solution.
Branch and Bound:?
Approaches to Solve a problem
Algorithm Greedy(a,n)
{
for i=1 to n do
{
x=select(a);
if feasible(x) then
solution=solution+x;
}
}
An activity-selection problem
do not overlap
Activity-Selection
Formally:
Given a set S of n activities
si = start time of activity i
fi = finish time of activity i
Find max-size subset A of compatible
activities
3
4 6
2
1 5
Assume that f1 f2 … fn
An activity-selection problem