This presentation focus on the optimization problem-solving method i.e. greedy method. It also included a basic definition, components of the algorithm, effective steps, general algorithm, and applications.
1. Prepared By:
Dr. Chandan Kumar
Assistant Professor, Computer Science & Engineering Department
Invertis University, Bareilly
2. Introduction
To understand greedy algorithm, firstly we must know
about
Optimization problem
Feasible solution
Optimal solution
3. Optimization Problem
An optimization problem is one in which you want to find,
not just a solution, but the best solution
An optimization problem which demands or requires
either minimum result or maximum result
4. Optimization Problem
Example
P : X ------700 KM-------------->Y
Where P is a problem, X and Y are the locations.
Here, I want to travel from location X to location Y. Now,
for this problem may be more than one solutions. Such
as, S1- travel by auto S4- Travel by bus
S2- Travel by bike S5- Travel by train
S3- Travel by car S6- Travel by airplane
and so on
5. Optimization Problem
But here is a condition that complete this journey within 10
hours.
We cannot complete this journey by solutions S1, S2, S3 but
cover by solution S4,S5 and S6. Hence, solutions S4, S5 and
S6 are called feasible solutions ( A solution which satisfies a
condition for the given problem).
Now I want to cover this journey at minimum cost i.e. we
want to minimize the problem. Suppose the train fare is
minimum then solution S5 is called optimal solution.
6. Optimization Problem
For any problem, there is only one optimal solution.
Similarly, some problems required maximum results.
Hence, if a problem requires either minimum or maximum
results than we call that type of problem as an optimization
problem.
The greedy method is used for solving optimization
problems.
7. Optimization Problem
For solving optimization problem there are three strategies
Greedy Method
Dynamic Programming
Branch and Bound
8. Greedy Method
Simplest and straightforward approach, among all the
algorithmic approaches.
Easy to implement and quite efficient.
Greedy algorithms build a solution part by part, choosing
the next part in such a way, that it gives an immediate
benefit. This approach never reconsiders the choices taken
previously.
In this approach, the decision is taken on the basis of
currently available information without worrying about the
effect of the current decision in future.
9. Greedy Method
Suppose that a problem can be solved by a sequence of
decisions. The greedy method has that each decision is locally
optimal. These locally optimal solutions will finally add up to
a globally optimal solution.
10. Greedy Algorithm
The algorithm makes the optimal choice at each step as it
attempts to find the overall optimal way to solve the entire
problem.
• A greedy algorithm works in phases. At each phase:
– You take the best you can get right now, without regard
for future consequences
– You hope that by choosing a local optimum at each step,
you will end up at a global optimum
11. Greedy Algorithm
Components- Greedy algorithms have the following five
components
A candidate set − A solution is created from this set.
A selection function − Used to choose the best
candidate to be added to the solution.
A feasibility function − Used to determine whether a
candidate can be used to contribute to the solution.
An objective function − Used to assign a value to a
solution or a partial solution.
A solution function − Used to indicate whether a
complete solution has been reached.
12. Greedy Algorithm
Steps for achieving a Greedy Algorithm are
Feasible: Here we search to see whether it meets all
possible constraints or not, to get at least one solution to
our problems.
Local Optimal Choice: In this, the optimal option that
is selected from the currently available should be
Unalterable: After taking a decision , the choice is not
altered at any subsequent stage.
13. Algorithm
Algorithm Greedy (x,n) // n is an input size and x is an input
{
for i= 1 to n do
{
y=select(x);
if feasible(y) then
{
solution=solution + y;
}
}
}
14. Application
Greedy method is used to solve a variety of problems
including
Finding the shortest path between two vertices using
Dijkstra’s algorithm
Finding the minimal spanning tree in a graph using
Prim’s /Kruskal’s algorithm
Networking algorithm also uses greedy approach like
Travelling Salesman Problem, Graph - Map Coloring
,Graph - Vertex Cover, Knapsack Problem, Job
Scheduling Problem etc.