Algorithm of JAVA Core Knowledge Points (2): Supplement

Pruning algorithm

In the optimization of the search algorithm, pruning is to avoid some unnecessary traversal processes through certain judgments. To put it vividly, it is to cut some "branches" in the search tree, so it is called pruning. The core problem of applying pruning optimization is to design a pruning judgment method, that is, a method of determining which branches should be discarded and which branches should be retained.
Insert picture description here

Backtracking algorithm

The backtracking algorithm is actually a search trial process similar to enumeration, which is mainly to find the solution of the problem in the search trial process. When it is found that the solution condition is not satisfied, it will "backtrack" and return and try another path.

Shortest path algorithm

Starting from a vertex, in the path taken by the edge of the graph to reach another vertex, the path with the smallest sum of weights on each edge is called the shortest path. There are the following algorithms to solve the shortest path problem, Dijkstra algorithm, Bellman-Ford algorithm, Floyd algorithm and SPFA algorithm.

Maximum subarray algorithm

Longest Common Subsequence Algorithm

Minimum spanning tree algorithm

Now suppose there is a very practical problem: we want to establish a communication network in n cities, then n-1 communication lines need to be arranged to connect these n cities. At this time, we need to consider how to establish this at the lowest cost. Communication network?
So we can introduce a connected graph to solve the problem we encountered. The n cities are the n vertices on the graph. Then, the edges represent the communication lines of the two cities, and the weight on each edge is the place where we build this line. The cost required, so now we have a connected network with n vertices to build different spanning trees, and each spanning tree can be used as a communication network. When the cost of constructing this connected network is minimal, build the connected network The spanning tree is called the minimum spanning tree.
There are many algorithms for constructing a minimum spanning tree, but they all use the same property of the minimum spanning tree: MST property (assuming N=(V,{E}) is a connected network, U is a non-empty subset of the vertex set V , If (u, v) is an edge with the smallest weight, where u belongs to U and v belongs to VU, then there must be a minimum spanning tree containing edges (u, v)), the following two kinds of use of MST Algorithms for generating minimum spanning trees: Prim's algorithm and Kruskal's algorithm

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_46914021/article/details/109215209