Greedy Algorithms works step-by-step, and always chooses the steps which provide immediate profit/benefit. It chooses the “locally optimal solution”, without thinking about future consequences. Greedy algorithms may not always lead to the optimal global solution, because it does not consider the entire data. The choice made by the greedy approach does not consider the future data and choices.

**All greedy algorithms follow a basic structure:**

getOptimal(Item, arr[], int n) 1) Initialize empty result : result = {} 2) While (All items are not considered) // We make a greedy choice to select // an item. i = SelectAnItem() // If i is feasible, add i to the // result if (feasible(i)) result = result U i 3) return result

**Characteristics of Greedy approach**

1. There is an ordered list of resources(profit, cost, value, etc.)

2. Maximum of all the resources(max profit, max value, etc.) are taken.

3. For example, in fractional knapsack problem, the maximum value/weight is taken first according to available capacity.

**Applications of Greedy Algorithms**

1. Finding an optimal solution (Activity selection, Fractional Knapsack, Job Sequencing, Huffman Coding).

2. Finding close to the optimal solution for NP-Hard problems like TSP.

**Advantages and Disadvantages of Greedy Approach**

**Advantages**

- Greedy approach is easy to implement.
- Typically have less time complexities.
- Greedy algorithms can be used for optimization purposes or finding close to optimization in case of NP Hard problems.

**Disadvantages**

- The local optimal solution may not always be global optimal.

- Activity Selection Problem
- Egyptian Fraction
- Job Sequencing Problem
- Job Sequencing Problem (Using Disjoint Set)
- Huffman Coding
- Water Connection Problem
- Policemen catch thieves
- Minimum Swaps for Bracket Balancing
- Fitting Shelves Problem
- Kruskal’s Minimum Spanning Tree
- Prim’s Minimum Spanning Tree
- Boruvka’s Minimum Spanning Tree
- Reverse delete algorithm for MST
- Dijkastra’s Shortest Path Algorithm

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Top 20 Greedy Algorithms Interview Questions
- Correctness of Greedy Algorithms
- Applications of String Matching Algorithms
- Maximum profit by buying and selling a share at most K times | Greedy Approach
- Activity Selection Problem | Greedy Algo-1
- Huffman Coding | Greedy Algo-3
- Prim’s MST for Adjacency List Representation | Greedy Algo-6
- Dijkstra's shortest path algorithm | Greedy Algo-7
- Graph Coloring | Set 2 (Greedy Algorithm)
- K Centers Problem | Set 1 (Greedy Approximate Algorithm)
- Set Cover Problem | Set 1 (Greedy Approximate Algorithm)
- Boruvka's algorithm | Greedy Algo-9
- Greedy Algorithm to find Minimum number of Coins
- Coin game of two corners (Greedy Approach)
- Greedy approach vs Dynamic programming
- Minimum number of subsequences required to convert one string to another using Greedy Algorithm
- Dijkstra’s Algorithm for Adjacency List Representation | Greedy Algo-8
- Kruskal’s Minimum Spanning Tree Algorithm | Greedy Algo-2
- Prim’s Minimum Spanning Tree (MST) | Greedy Algo-5
- Efficient Huffman Coding for Sorted Input | Greedy Algo-4

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.