Bansari Shah's document discusses greedy algorithms. It defines greedy algorithms as making locally optimal choices at each step to find a global optimum. The document outlines the characteristics, optimization problems, pseudo-code for greedy algorithms, and provides an example of Prim's algorithm. It also compares greedy algorithms to dynamic programming and discusses pros and cons, such as greedy algorithms being faster but not always reaching the global optimum.
2. OUTLINE
Greedy introduction
Characteristics and features
Optimization Problem
Pseudo code for greedy algorithm
Greedy approach
Prim’s algorithm
Comparison with DP
Pros and Cons
2
3. GREEDY INTRODUCTION
Greedy algorithms are simple and
straightforward.
Greedy have top down approach.
They are shortsighted in their approach.
A greedy method is an method that follows
the problem solving technique of making the
locally optimal choice at each stage with the
hope of finding a global optimum.
3
4. CHARACTERISTICS AND FEATURES
To construct the solution in an optimal way.
Algorithm Maintains two sets,
-One contains chosen items and
-The other contains rejected items.
Greedy algorithms make good local choices in
the hope that They result in,
-An optimal solution.
-Feasible solutions.
4
5. CONTINUED…
The greedy algorithm consists of four (4) function.
Solution function: A function that checks whether chosen
set of items provide a solution.
Feasible solution: A function that checks the feasibility of
a set.
Selection solution: The selection function tells which of
the items is the most promising.
Objective solution: An objective function, which does not
appear explicitly, gives the value of a solution.
5
6. OPTIMIZATION PROBLEMS
An optimization problem:
Given a problem instance, a set of constraints and
an objective function.
Find a feasible solution for the given instance for
which the objective function has an optimal value.
Either maximum or minimum depending on the
problem being solved. A feasible solution that does
this is called optimal solution.
6
8. GREEDY PROPERTY
It consists of two property,
1. "greedy-choice property" ->It says that a globally
optimal solution can be arrived at by making a
locally optimal choice.
2. "optimal substructure" ->A problem exhibits
optimal substructure if an optimal solution to
the problem contains optimal solutions to the
sub-problems.
8
9. PSEUDO-CODE FOR GREEDY
ALGORITHM
Algorithm Greedy (a,n)
//a[1:n]contains the n inputs.
{
solution:=0;//initialize the solution.
for i=1 to n do
{
x=Select(a);
if Feasible( solution, x) then
solution:=Union(solution , x);
}
return solution;
}
9
10. CONTINUED…
Select() selects an input from a[] and removes it.
the selected input value is assigned to x.
Feasible() is a Boolean - valued function that
determines whether x can be included into the
solution vector(no constraints are violated).
Union() combines x with the solution and updates
the objective function.
10
11. Greedy approach
PRIM’S ALGORITHM:
Prim's algorithm is a greedy algorithm that finds
a minimum spanning tree for a connected weighted
undirected graph. This means it finds a subset of
the edges that forms a tree that includes
every vertex, where the total weight of all
the edges in the tree is minimized.
11
23. PROS AND CONS
PROS:
They are easier to implement,
they require much less computing resources,
they are much faster to execute.
Greedy algorithms are used to solve optimization problems
CONS:
Their only disadvantage being that they not always reach the
global optimum solution;
on the other hand, even when the global optimum solution
is not reached, most of the times the reached sub-optimal
solution is a very good solution.
23