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)06/01 Report--
This article introduces the relevant knowledge of "how to realize the Java retrospective method". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Overview
The simple description of the retrospective method is that the solution space of the problem is transformed into the structural representation of the graph or tree, and then traversed by the depth-first search strategy, all feasible solutions or optimal solutions are recorded and found in the traversal process.
The basic idea is similar to:
Depth-first search of graphs
Post-order traversal of binary trees
The detailed description is:
The backtracking method searches the solution space tree of the problem according to the depth-first strategy. First of all, the solution space tree is searched from the root node. when the algorithm searches to a node of the solution space tree, the pruning function is used to determine whether the node is feasible (that is, the solution of the problem can be obtained). If it is not feasible, skip the search of the subtree whose root is the node and trace back to its ancestor node layer by layer; otherwise, enter the subtree and continue to search according to the depth-first strategy.
The basic behavior of the backtracking method is search, and the search process uses pruning functions to avoid invalid searches. Pruning functions include two types: 1. Use the constraint function to cut out the paths that do not meet the constraints; 2. Using the bounded function, cut out the path that can not get the optimal solution.
The key to the problem is how to define the solution space of the problem and transform it into a tree (that is, the solution space tree). There are two kinds of solution space trees: subset trees and permutation trees. The structures and ideas of the two algorithms are roughly the same.
Mode of realization
There are two ways to implement the backtracking method: recursion and recursion (also known as iteration). Generally speaking, both methods of one problem can be implemented, but there are differences in algorithm efficiency and design complexity.
[analogous to the recursive implementation and non-recursive (recursive) implementation of graph depth traversal]
Recursion
The idea is simple, the design is easy, but the efficiency is low. The design paradigm is as follows:
Void backtrack (int t) {if (t > n) output (x); / / Leaf node, output the result, x is the feasible solution else for i = 1 to k _ b / all the children of the current node {x [t] = value (I) / / the value of each child node is assigned to x / / satisfying the constraint and bound conditions if (constraint (t) & & bound (t)) backtrack (tweak 1); / / Recursive lower layer}} Recursive void iterativeBacktrack () {int twee1 While (t > 0) {if (ExistSubNode (t)) / / the existing child node of the current node {for I = 1 to k / / traverses all the child nodes of the current node {x [t] = value (I) / / the value of each child node is assigned to x if (constraint (t) & & bound (t)) / / satisfies the constraint and bound conditions {/ / solution means that a solution if (solution (t)) output (x) is obtained at node t. / / get a feasible solution to the problem, output else tweeters / no solution, continue to search down} else / / there are no child nodes, and return to the previous layer {tmuri- This is the end of the content of "how to implement the Java retrospective method". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.