Greedy Algorithms

An algorithm is designed to find the best solution to a given problem. The greedy algorithm approach makes decisions based on the given solution domain. As a greedy person, the closest solution that appears to provide the best solution is chosen.

Greedy algorithms seek a locally optimised solution, which may eventually lead to globally optimised solutions. However, greedy algorithms do not always provide globally optimised solutions.

  • Counting Coins — The problem is to count to a desired value by selecting the fewest coins possible, and the greedy approach forces the algorithm to select the largest coin possible. If we are given coins numbered 1, 2, 5, and 10 and asked to count 18, the greedy procedure will be followed.

1 − Select one ₹ 10 coin, the remaining count is 8

2 − Then select one ₹ 5 coin, the remaining count is 3

3 − Then select one ₹ 2 coin, the remaining count is 1

4 − And finally, the selection of one ₹ 1 coins solves the problem

Though it appears to be working properly, we only need to select four coins for this count. However, if we slightly alter the problem, the same approach may not produce the same optimal result.

In a currency system with coins of 1, 7, and 10 values, counting coins for value 18 is absolutely optimal, but counting coins for value 15 may use more coins than necessary. The greedy approach, for example, will use 10 + 1 + 1 + 1 + 1, for a total of 6 coins. Alternatively, the same problem could be solved with only three coins (7 + 7 + 1). As a result, we can conclude that the greedy approach selects an immediately optimised solution and may fail where global optimization is important.

  • Divide and Conquer – The divide and conquer approach divides the problem at hand into smaller sub-problems, which are then solved independently. If we continue to divide the subproblems into smaller and smaller subproblems, we may eventually reach a point where no further division is possible. The smallest “atomic” sub-problems (fractions) are solved. The solutions to all sub-problems are finally merged to yield the solution to the original problem.
  • Divide – This step entails decomposing the problem into smaller sub-problems. Sub-problems should be a subset of the original problem. This step typically employs a recursive approach to divide the problem until no further sub-problems are divisible. Sub-problems become atomic in nature at this point, but they still represent some part of the overall problem.
  • Conquer – This step is given a large number of smaller sub-problems to solve. At this level, problems are generally considered solved on their own.
  • Merge/ Combine – When the smaller sub-problems are solved, this stage combines them recursively until they form a solution to the original problem. This algorithmic approach works recursively, and the conquer and merge steps are so close together that they appear to be one.
0

11 thoughts on “Greedy Algorithms”

  1. Thank you for another excellent article. Where else could anyone get that kind of info in such a perfect way of writing? I’ve a presentation next week, and I’m on the look for such info.

    0
  2. I found your weblog site on google and test a couple of of your early posts. Continue to maintain up the superb operate. I simply additional up your RSS feed to my MSN Information Reader. Seeking forward to reading more from you in a while!…

    0
  3. I’ve been browsing online more than three hours lately, but I by no means found any fascinating article like yours. It’s pretty worth sufficient for me. Personally, if all website owners and bloggers made just right content material as you probably did, the internet can be much more useful than ever before. “Baseball is 90 percent mental. The other half is physical.” by Lawrence Peter Berra.

    0
  4. Hello there! Do you know if they make any plugins to assist with Search Engine Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good success. If you know of any please share. Kudos!

    0
  5. An impressive share, I just given this onto a colleague who was doing a little analysis on this. And he in fact bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love reading more on this topic. If possible, as you become expertise, would you mind updating your blog with more details? It is highly helpful for me. Big thumb up for this blog post!

    0
  6. Please let me know if you’re looking for a article author for your weblog. You have some really great posts and I believe I would be a good asset. If you ever want to take some of the load off, I’d really like to write some material for your blog in exchange for a link back to mine. Please send me an e-mail if interested. Thank you!

    0

Leave a Comment

Your email address will not be published. Required fields are marked *