In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
In this article Xiaobian for you to introduce in detail "what are the commonly used algorithms in Java", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what are the commonly used algorithms in Java" can help you solve your doubts.
Greedy algorithm (greedy algorithm)
Classic applications: such as Huffman coding (Huffman Coding), Prim and Kruskal minimum spanning tree algorithm, and Dijkstra single-source shortest path algorithm.
The steps of greedy algorithm to solve the problem
The first step, when we see this kind of problem, we should first associate with the greedy algorithm: for a set of data, we define the limit value and the expected value, hope to select several data, in the case of meeting the limit value, the expected value is the largest.
Compared to the example just now, the limit value is that the weight cannot exceed 100kg, and the expected value is the total value of the item. This set of data is five kinds of beans. We select a part of it to satisfy that the weight does not exceed 100kg and the total value is the largest.
In the second step, we try to see if this problem can be solved by greedy algorithm: each time we choose the current situation, the data that contributes the most to the expected value with the same amount of contribution to the limit value.
In the analogy to the example just now, we always choose the beans with the highest unit price, that is, the beans with the same weight, which contribute the most to the value from the remaining beans.
In the third step, let's give several examples to see whether the result produced by greedy algorithm is optimal. In most cases, just give a few examples to verify it. Strictly proving the correctness of greedy algorithm is very complex and requires a lot of mathematical reasoning.
The main reason why the greedy algorithm does not work is that the previous choice will affect the later choice.
Actual combat analysis of greedy algorithm
1. Divide the candy
We have m candies and n children. We are going to give candy to these children now, but there are fewer candies and more children (m).
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.