Greedy Algorithms

  • Last Updated : 22 Nov, 2022

Data Structure and Algorithms Course
Practice Problems on Greedy Algorithms
Recent Articles on 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 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.


Standard Greedy Algorithms :


Greedy Algorithms in Graphs :

Greedy Algorithms in Arrays :

Greedy Algorithms in Operating Systems :

Approximate Greedy Algorithms for NP Complete Problems :

Greedy Algorithms for Special Cases of DP problems :

Misc :

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

Quick Links :

  1. Learn Data Structure and Algorithms | DSA Tutorial
  2. Top 20 Greedy Algorithms Interview Questions
  3. ‘Practice Problems’ on Greedy Algorithms
  4. Practice Questions on Huffman Encoding
  5. ‘Quiz’ on Greedy Algorithms

GeeksforGeeks Courses:

1. Language Foundation Courses [C++ / JAVA / Python ]
Learn any programming language from scratch and understand all its fundamentals concepts for a strong programming foundation in the easiest possible manner with help of GeeksforGeeks Language Foundation Courses – Java Foundation | Python Foundation | C++ Foundation

2. Complete Interview Preparation
Get fulfilled all your interview preparation needs at a single place with the Complete Interview Preparation Course that provides you all the required stuff to prepare for any product-based, service-based, or start-up company at the most affordable prices.

3. DSA Self Paced
Start learning Data Structures and Algorithms to prepare for the interviews of top IT giants like Microsoft, Amazon, Adobe, etc. with DSA Self-Paced Course where you will get to learn and master DSA from basic to advanced level and that too at your own pace and convenience.

4. Company Specific Courses – Amazon & Microsoft
Crack the interview of any product-based giant company by specifically preparing with the questions that these companies usually ask in their coding interview round. Refer GeeksforGeeks Company Specific Courses: Amazon SDE Test Series, etc.

If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to 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.

My Personal Notes arrow_drop_up