#Algorithms
## What is a Greedy algorithm?

## Where can we use the Greedy algorithm?

## How do you decide which choice is optimal?

## Advantages and disadvantages of Greedy algorithm:

## Application of Greedy algorithm.

In the programming world, there is no such technique that solves all computation problems. We need to apply various kinds of techniques for various problems. Some commonly used techniques are-

1. Divide and conquer

2. Randomized algorithms

3. Greedy algorithms

4. Dynamic programming

Note: Greedy is a technique, not an algorithm.

Here we are going to understand what, where, how, and when we can use the technique i.e Greedy algorithm.

A Greedy Algorithm always makes the choice that looks best at the moment. We make the locally optimal choice in the hope that it will lead us to the global optimal solution.

The Greedy method is quite powerful and works well for a wide range of problems. We can use the Greedy algorithm whenever we have to either maximize or minimize the problem.

We use Greedy method in the following algorithms:

1. Minimum-spanning-tree algorithm

2. Dijkstra Algorithm

3. Huffman Data-compression

Basic Structure of a Greedy algorithm.

Optimal_greedy_fun(Item, arr[], int n)

1) Initialize empty result : result = ()

2) While (Iterate for all values)

// Make your greedy choice to select item.

i = SelectAnItem()

// If i is feasible, add i to the result

if (feasible(i))

result = result U i

// finally return result

3) return result

There are mostly two kinds of problems in optimization maximization or minimization. Assume that you have an objective function that needs to be optimized (either maximized or minimized) at a given point.

A Greedy algorithm makes greedy choices at each level of computation to ensure that the objective function is optimized. It has only one chance to compute the optimal solution, it never gets back to the previous decision.

1. When we solve an optimization problem first we came up with a Greedy solution.

2. Compare to other algorithms run time analysis of greedy is easier than others like divide and Conquer.

3. The disadvantage of Greedy is that it is very hard to prove that your solution and algorithm are correct.

Note: Most greedy algorithms are not optimized and correct.

The greedy method is quite powerful and works well for various ranges of problems. Many algorithms can be viewed as applications of the Greedy algorithms, a few of them are:

1. Minimum Spanning Tree.

2. Dijkstra’s algorithm for finding the shortest paths from a single source.

3. Huffman codes (for Data compression).

Thanks for reading!!!

Explore more

#Python #Motivation #SQL #Hackerrank #Selenium #AI #Testing #Interview #JavaScript #Java #GPT #React.js #Machine learning #API #IT #Algorithms #Microservice #Linux #Cucumber #Google #Jobs #Django #AWS #Jupyter #Pip #Database #Postman #Health #Silq #Virtualenv #Data Science #SQL Developer #Rest Assured #Github #Projects #Puzzle #Cypress #Appium

#Python #Motivation #SQL #Hackerrank #Selenium #AI #Testing #Interview #JavaScript #Java #GPT #React.js #Machine learning #API #IT #Algorithms #Microservice #Linux #Cucumber #Google #Jobs #Django #AWS #Jupyter #Pip #Database #Postman #Health #Silq #Virtualenv #Data Science #SQL Developer #Rest Assured #Github #Projects #Puzzle #Cypress #Appium

Related Blogs

View More

Top 8 Algorithms every programmer should Know !!!

Author: neptune | 21st-Apr-2023 | Views: 70

#Algorithms

The top 8 algorithms for programmers include sorting, searching, graph, dynamic programming, greedy, divide and conquer, backtracking, and randomized...

Author: neptune | 21st-Apr-2023 | Views: 70

#Algorithms

The top 8 algorithms for programmers include sorting, searching, graph, dynamic programming, greedy, divide and conquer, backtracking, and randomized...

View More

anonymous | May 11, 2022, 12:09 a.m.

Well explained 👍