[Introduction to Algorithms] greedy algorithm (greedy algorithm)

Source: Internet
Author: User

Reprint Please specify source: http://www.cnblogs.com/StartoverX/p/4611544.html

The greedy algorithm makes the best-looking choice at the time of every step. In other words, it always makes local optimal choice, hoping (proving) that such a choice can lead to a global optimal solution.

Both greedy algorithm and dynamic programming depend on the optimal substructure , that is, the optimal solution of a problem contains the optimal solution of its sub-problem. The difference is that dynamic programming usually requires solving each sub-problem, and the solution to the problem is obtained by solving all the child problems. The greedy algorithm hopes to improve the optimal substructure by greedy selection, so that only one sub-problem is left after each selection , which greatly simplifies the problem solving process. So the problem of being able to use the greedy algorithm contains some special conditions that need to be carefully detected. The relationship between greedy algorithm and dynamic programming allows us to conclude that there is almost always a more tedious dynamic programming algorithm under each greedy algorithm.

The greedy algorithm steps:

1. Transform the optimization problem into this form: Once a selection has been made, only one sub-problem needs to be solved.

2. After proving the greedy choice, the original problem always has the optimal solution, that is, the greedy choice is always safe.

3. After proving the greedy choice, the remaining sub-problem satisfies the nature: the optimal solution of the original problem can be obtained by combining the optimum and greedy selection, and the optimal substructure is obtained.

Example: Leetcode Jump game:http://www.cnblogs.com/startoverx/p/4611518.html

[Introduction to Algorithms] greedy algorithm (greedy algorithm)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.