Greedy Algorithms
Learn more about Greedy Algorithms in DSA Self Paced Course
Practice Problems on Greedy Algorithms
Top Quizzes on Greedy Algorithms
What is Greedy Algorithm?
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 the 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 a globally optimal solution because we are allowed to take fractions of an item.
Topics:
 Introduction to Greedy Algorithm – Data Structures and Algorithm Tutorials
 Greedy Algorithms (General Structure and Applications)
 Difference between Greedy Algorithm and Divide and Conquer Algorithm
 Greedy approach vs Dynamic programming
 Comparison among Greedy, Divide and Conquer and Dynamic Programming algorithm
 Activity Selection Problem
 Job Sequencing Problem
 Huffman Coding
 Huffman Decoding
 Water Connection Problem
 Minimum Swaps for Bracket Balancing
 Egyptian Fraction
 Policemen catch thieves
 Fitting Shelves Problem
 Assign Mice to Holes
 Minimum product subset of an array
 Maximize array sum after K negations using Sorting
 Minimum sum of product of two arrays
 Minimum sum of absolute difference of pairs of two arrays
 Minimum increment/decrement to make array nonIncreasing
 Sorting array with reverse around middle
 Sum of Areas of Rectangles possible for an array
 Largest lexicographic array with atmost K consecutive swaps
 Partition into two subarrays of lengths k and (N – k) such that the difference of sums is maximum
Greedy Problems on Operating System:
 First Fit algorithm in Memory Management
 Best Fit algorithm in Memory Management
 Worst Fit algorithm in Memory Management
 Shortest Job First Scheduling
 Job Scheduling with two jobs allowed at a time
 Program for Optimal Page Replacement Algorithm
 Kruskal’s Minimum Spanning Tree
 Prim’s Minimum Spanning Tree
 Boruvka’s Minimum Spanning Tree
 Dijkastra’s Shortest Path Algorithm
 Dial’s Algorithm
 Minimum cost to connect all cities
 Max Flow Problem Introduction
 Number of single cycle components in an undirected graph
Approximate Greedy Algorithm for NP Complete:
 Set cover problem
 Bin Packing Problem
 Graph Coloring
 Kcenters problem
 Shortest superstring problem
 Approximate solution for Travelling Salesman Problem using MST
Greedy for Special cases of DP:
Some practice problems on Greedy:

Easy:
 Split n into maximum composite numbers
 Buy Maximum Stocks if i stocks can be bought on ith day
 Find the minimum and maximum amount to buy all N candies
 Maximum sum possible equal to sum of three stacks
 Divide cuboid into cubes such that sum of volumes is maximum
 Maximum number of customers that can be satisfied with given quantity
 Minimum rotations to unlock a circular lock
 Minimum rooms for m events of n batches with given schedule
 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 increment by k operations to make all elements equal
 Find minimum number of currency notes and values that sum to given amount
 Smallest subset with sum greater than all other elements

Medium:
 Maximum trains for which stoppage can be provided
 Minimum Fibonacci terms with sum equal to K
 Divide 1 to n into two groups with minimum sum difference
 Paper cut into minimum number of squares
 Minimum difference between groups of size two
 Connect n ropes with minimum cost
 Minimum number of Platforms required for a railway/bus station
 Minimum initial vertices to traverse whole matrix with given conditions
 Largest palindromic number by permuting digits
 Find Smallest number with given number of digits and digits sum
 Lexicographically largest subsequence such that every character occurs at least k times

Hard:
 Maximum elements that can be made equal with k updates
 Minimize cash flow among friends
 Minimum Cost to cut a board into squares
 Minimum cost to process m tasks where switching costs
 Minimum time to finish all jobs with given constraints
 Minimize the maximum difference between the heights of towers
 Minimum edges to reverse to make path from a source to a destination
 Find the Largest Cube formed by Deleting minimum Digits from a number
 Rearrange characters in a string such that no two adjacent are same
 Rearrange a string so that all same characters become d distance away
 Learn Data Structure and Algorithms  DSA Tutorial
 Top 20 Greedy Algorithms Interview Questions
 ‘Practice Problems’ on Greedy Algorithms
 ‘Quiz’ on Greedy Algorithms
If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to reviewteam@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.