# Greedy Algorithms

Greedy is an algorithmic paradigm that builds up a solution piece by piece, always choosing the next piece that offers the most obvious and immediate benefit. So the problems where choosing locally optimal also leads to global solution are best fit for Greedy.

For example consider the Fractional Knapsack Problem. The local optimal strategy is to choose the item that has maximum value vs weight ratio. This strategy also leads to global optimal solution because we allowed to take fractions of an item.

### Recent Articles on Greedy Algorithms !

- Activity Selection Problem
- Egyptian Fraction
- Job Sequencing Problem
- Job Sequencing Problem (Using Disjoint Set)
- Job Sequencing Problem – Loss Minimization
- Job Selection Problem – Loss Minimization Strategy | Set 2
- Huffman Coding
- Efficient Huffman Coding for sorted input
- Huffman Decoding
- Water Connection Problem
- Policemen catch thieves
- Minimum Swaps for Bracket Balancing
- Fitting Shelves Problem
- Assign Mice to Holes

- Kruskal’s Minimum Spanning Tree
- Prim’s Minimum Spanning Tree
- Boruvka’s Minimum Spanning Tree
- Reverse delete algorithm for MST
- Problem Solving for Minimum Spanning Trees (Kruskal’s and Prim’s)
- Dijkastra’s Shortest Path Algorithm
- Dial’s Algorithm
- Dijkstra’s Algorithm for Adjacency List Representation
- Prim’s MST for adjacency list representation
- Correctness of Greedy Algorithms
- Minimum cost to connect all cities
- Max Flow Problem Introduction
- Number of single cycle components in an undirected graph

- Minimum product subset of an array
- Maximum product subset of an array
- Maximize array sum after k-negations | Set 1
- Maximize array sum after k-negations | Set 2
- Maximize the sum of arr[i]*i
- Maximum sum of increasing order elements from n arrays
- Maximum sum of absolute difference of an array
- Maximize sum of consecutive differences in a circular array
- Maximum height pyramid from the given array of objects
- Partition into two subarrays of lengths k and (N – k) such that the difference of sums is maximum
- Minimum sum of product of two arrays
- Minimum sum by choosing minimum of pairs from array
- Minimum sum of absolute difference of pairs of two arrays
- Minimum operations to make GCD of array a multiple of k
- Minimum sum of absolute difference of pairs of two arrays
- Minimum sum of two numbers formed from digits of an array
- Minimum increment/decrement to make array non-Increasing
- Making elements of two arrays same with minimum increment/decrement
- Minimize sum of product of two arrays with permutation allowed
- Sorting array with reverse around middle
- Sum of Areas of Rectangles possible for an array
- Array element moved by k using single moves
- Find if k bookings possible with given arrival and departure times
- Lexicographically smallest array after at-most K consecutive swaps
- Largest lexicographic array with at-most K consecutive swaps

**Greedy Algorithms in Operating Systems : **

**Approximate Greedy Algorithms for NP Complete Problems :**

**Greedy Algorithms for Special Cases of DP problems :**

- Split n into maximum composite numbers
- Maximum trains for which stoppage can be provided
- Buy Maximum Stocks if i stocks can be bought on i-th day
- Find the minimum and maximum amount to buy all N candies
- Maximum sum possible equal to sum of three stacks
- Maximum elements that can be made equal with k updates
- Divide cuboid into cubes such that sum of volumes is maximum
- Maximum number of customers that can be satisfied with given quantity
- Minimum Fibonacci terms with sum equal to K
- Divide 1 to n into two groups with minimum sum difference
- Minimize cash flow among friends
- Minimum rotations to unlock a circular lock
- Paper cut into minimum number of squares
- Minimum difference between groups of size two
- Minimum rooms for m events of n batches with given schedule
- Connect n ropes with minimum cost
- Minimum Cost to cut a board into squares
- Minimum cost to process m tasks where switching costs
- Minimum cost to make array size 1 by removing larger of pairs
- Minimum cost for acquiring all coins with k extra coins allowed with every coin
- Minimum time to finish all jobs with given constraints
- Minimum number of Platforms required for a railway/bus station
- Minimize the maximum difference between the heights of towers
- Minimum increment by k operations to make all elements equal
- Minimum edges to reverse to make path from a source to a destination
- Find minimum number of currency notes and values that sum to given amount
- Minimum initial vertices to traverse whole matrix with given conditions
- Find the Largest Cube formed by Deleting minimum Digits from a number
- Check if it is possible to survive on Island
- Largest palindromic number by permuting digits
- Smallest number with sum of digits as N and divisible by 10^N
- Find Smallest number with given number of digits and digits sum
- Rearrange characters in a string such that no two adjacent are same
- Rearrange a string so that all same characters become d distance away
- Print a closest string that does not contain adjacent duplicates
- Smallest subset with sum greater than all other elements
- Lexicographically largest subsequence such that every character occurs at least k times

- Top 20 Greedy Algorithms Interview Questions
- ‘Practice Problems’ on Greedy Algorithms
- Practice Questions on Huffman Encoding
- ‘Quiz’ on Greedy Algorithms

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

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.