Greedy Algorithm
Greedy algorithms1 are a class of algorithms that make locally optimal choices at each step with the hope of finding a global optimum solution.
The greedy algorithm makes the best choice at each step as it attempts to find the overall optimal way to solve the entire problem. The name of this algorithm, greedy, greedy, is the key to its inherent meaning. It's like a greedy person who always wants the best thing in front of him, can't see the long-term, and doesn't think about the final result and the future, and seeks to maximize the local benefits in front of him, a bit like walking one step at a time.
贪心算法2,又名贪婪法,是寻找最优解问题的常用方法,这种方法模式一般将求解过程分成若干个步骤,但每个步骤都应用贪心原则,选取当前状态下最好/最优的选择(局部最有利的选择),并以此希望最后堆叠出的结果也是最好/最优的解。看着这个名字,贪心,贪婪这两字的内在含义最为关键。这就好像一个贪婪的人,他事事都想要眼前看到最好的那个,看不到长远的东西,也不为最终的结果和将来着想,贪图眼前局部的利益最大化,有点走一步看一步的感觉。
贪心算法3与动态规划(Dynamic Programming)的不同在于它对每个子问题的解决方案都做出选择,不能回退。动态规划则会保存以前的运算结果,并根据以前的结果对当前进行选择,有回退功能。