0% found this document useful (0 votes)
20 views

Greedy Algorithm

1. Greedy algorithms work in stages, making locally optimal choices at each stage without considering future consequences. This assumes local optimal choices lead to a global optimal solution. 2. For a greedy algorithm to work correctly, it requires two properties: the greedy choice property and optimal substructure. The greedy choice property means the optimal solution can be reached through locally optimal choices. Optimal substructure means optimal solutions to subproblems combine to form an optimal solution to the overall problem. 3. Greedy algorithms are straightforward and easy to implement but do not always produce the best solution. They work well for problems like sorting, priority queues, Huffman coding, and some graph problems. Examples are given to illustrate greedy techniques.

Uploaded by

Bryce Nana
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Greedy Algorithm

1. Greedy algorithms work in stages, making locally optimal choices at each stage without considering future consequences. This assumes local optimal choices lead to a global optimal solution. 2. For a greedy algorithm to work correctly, it requires two properties: the greedy choice property and optimal substructure. The greedy choice property means the optimal solution can be reached through locally optimal choices. Optimal substructure means optimal solutions to subproblems combine to form an optimal solution to the overall problem. 3. Greedy algorithms are straightforward and easy to implement but do not always produce the best solution. They work well for problems like sorting, priority queues, Huffman coding, and some graph problems. Examples are given to illustrate greedy techniques.

Uploaded by

Bryce Nana
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Algorithm and

complexity
GREEDY ALGORITHMS
Introduction
Let us start our discussion simple theory that will give us an understanding of the greedy
technique. In the game of Cwithhess, every time we make a decision about a move, we have to
also think about the future consequences. Whereas, in the game of Tennis (or Volleyball), our
action is based on the immediate situation. This means that in some cases making a decision
that looks right at that moment gives the best solution (Greedy), but in other cases it doesn’t.
the greedy technique is best suited for looking at the immediate situation.
Greedy Strategy
Greedy algorithms work in stages. In each stage, a decision is made that is good at that point,
without bothering about the future. This means that some local best is chosen. It assume that a
local good selection makes for a global optimal solution.
Elements of greedy algorithms
The two basic properties of optimal greedy algorithms are:
1. Greedy choice property: this property saya that the globally optimal solution can be
obtained by making a locally optimal solution(greedy). The choice made by a greedy
algorithm may depend on earlier choices but not on the future. It iteratively make one
greedy choice after another and reduces the given problem to a smaller one.
2. Optimal substructure: a problem exhibits optimal substructure if an optimal solution to the
problem contains optimal solutions to the subproblems. That means we can solve
subproblems and build up the solutions to solve larger problems.
Does greegy always work?
Making locally optimal choices does not always work. Hence, greedy algorithms will not always
give the best solution. We will see particular examples.
Advantages and disadvantages of greedy
method
The main advantage of the greedy method is that it is straightforward, easy to understand and
easy to code. In greedy algorithms, once we make a decision, we do not have to spend time re-
examining the already computed values. Its main disadvantage is that for many problems there
is nogreedy algorithm. That means, in many cases there is no guarantee that making locally
optimal improvements in a locally optimal solution gives the optimal global solution
Greedy applications
Sorting: selection sort, Topological sort;
Pririty queues: Heap sort;
Huffman coding compression algorithm;
Prim’s and Kruskal’s algorithms;
Shortest path in weighted graph (Dijkstra’s)
Coin change problem;
Fractional Knapsak problem
Job scheduling algorithm
Greedy techniques can be used as an approximation algorithm for complex problems
Understanding greedy technique
For better understanding, let us go through an example
Understanding greedy technique
For better understanding, let us go through an example

You might also like