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.