Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 8

Design and

Analysis of
Algorithm

BS Cs 3rd

Prof Hashim Javed


Greedy Algorithm

 A greedy algorithm is a mathematical process that looks for simple,


easy-to-implement solutions to complex, multi-step problems by
deciding which next step will provide the most obvious benefit

 Such algorithms are called greedy because while the optimal solution
to each smaller instance will provide an immediate output, the
algorithm doesn’t consider the larger problem as a whole. Once a
decision has been made, it is never reconsidered
Greedy Algorithm Works on
following property

1. Greedy Choice property:


it makes locally optimal choice in the hope that this choice lead to
globally optimal Solution

2.Optimal Substructure:
Optimal solution contain optimal Sum Solution
Greedy Algorithm

What is Greedy Algorithm?

To find out the best Solution You have to be Greedy


so that best Solution can be taken
Example

3 1

A C
8

5 7
D
Considering the Above Diagram Suppose We have to move from A
to C
Then there are three possible Solutions
From A to B from B to C
From A to D from D to C
OR
Directly From A to C
But For this we have to calculate this
which is the most minimum solution for
this path For which we can travel Easily
Another Example

B
4
1

A C
10

5 2
D

You might also like