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

Greedy Algorithm

Uploaded by

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

Greedy Algorithm

Uploaded by

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

Greedy Algorithm

Algorithm
General Structure
• Identify the problem as an optimization problem where we need to
find the best solution among a set of possible solutions.
• Determine the set of feasible solutions for the problem.
• Identify the optimal substructure of the problem, meaning that the
optimal solution to the problem can be constructed from the optimal
solutions of its subproblems.
• Develop a greedy strategy to construct a feasible solution step by
step, making the locally optimal choice at each step.
Prove the correctness of the algorithm by showing that the locally
optimal choices at each step lead to a globally optimal solution.
General Structure
• Among all the algorithmic approaches, the simplest and
straightforward approach is the Greedy method. In this approach, the
decision is taken on the basis of current available information without
worrying about the effect of the current decision in future.
• 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. This approach is
mainly used to solve optimization problems.
Components of Greedy Algorithm
• 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.
Pros and Cons
Advantages Disadvantages

Efficiency Lack of Backtracking

Flexibility Sensitivity to Input

Intuition Limited Applicability

Approximation Difficulty in Analysis


Examples
• Most networking algorithms use the greedy approach. Here is a list of
few of them −
• Travelling Salesman Problem
• Prim's Minimal Spanning Tree Algorithm
• Kruskal's Minimal Spanning Tree Algorithm
• Dijkstra's Minimal Spanning Tree Algorithm

You might also like