[Algorithm review 1] common algorithm policy summary

Source: Internet
Author: User

I. Overview

There are differences between algorithm policies and algorithms. They are two aspects of algorithm design. algorithm policies are problem-oriented and algorithms are implementation-oriented;

However, the two are inseparable. First, the algorithms used to solve the problem are used to identify the algorithm. Second, the algorithms used to solve the problem are naturally different.


Ii. algorithm Policy

1) Recurrence strategy: Like greedy algorithms, the "progressive method" is gradually resolved by the current problem to obtain the solution of the entire problem. It only depends on the recursive relationship between information, each step does not require policies to be involved in algorithms. They are more used for computing.

2) recursive strategy: the recursive method uses the recursive relationship between the big problem and its subproblems to solve the problem. Find the relationship between a large problem and a small sub-problem every time, until the small sub-problem is easily solved, and then the solution of the big problem is derived from the small sub-problem .. Example: Tower of Hanoi Problem

3) exhaustive strategy: Try all possible solutions one by one.

4) Recursive Backtracking Strategy: similar to the concept of the exhaustive method, the Recursive Backtracking Method Uses recursion to repeat the paths that may be solved by the problem. If this path is unavailable, it goes back to the previous step and tries another path.

5) divide and conquer strategy: the solution is complicated. Such problems can be resolved by dividing them into independent subproblems, "merge" the solutions of two or more independent subproblems to obtain a larger subproblem, and finally merge the solutions to the total problem. (Note that it can be broken down into independent subproblems. Otherwise, public subproblems will be repeated)

6) dynamic planning strategy: the dynamic planning method is similar to the greedy method, and requires the problem to have an optimal sub-structure (that is, the optimal solution contains the optimal solution of the sub-problem). It is a bottom-up solution, in contrast to recursion, each time a stage is solved, the subproblems on which the phase is resolved have been completely solved, therefore, each step is solved until all required information is obtained. Therefore, the global optimal solution can be obtained.

7) greedy strategy: If you want to obtain the optimal solution, you must have more strict requirements on the nature of the problem. In addition to the optimal sub-structure, you must also have a greedy choice. Specifically, greedy is a strategy, that is, to choose the best option for each step. After this option is completed, the problem is converted into one (only one) subproblem, this is an ordered solution process. Each step is considered separately. Only local optimization is considered, because the subsequent subproblem is not solved, therefore, greedy algorithms cannot search for the entire solution space. Therefore, they generally cannot obtain the optimal solution. Unless the problem is greedy. The so-called greedy choice is that after a greedy choice, only one subproblem can be formed. In this way, the space for solving the problem is actually a linear space, and the greedy algorithm can obtain the optimal solution. It is a top-down solution.


3. Relationship between algorithm policies

1) division and Control Law and Dynamic Planning Law"

• It is the application of recursive ideas to find out the relationship between large problems and small subproblems until small subproblems are easily solved, then, a small subproblem is used to solve the big problem.

• One of the features of the divide-and-conquer method is that each subproblem is independent of each other. That is, subproblems do not include public subproblems.

• The essence of dynamic planning is to divide governance ideas and solve redundancy.

2) Try and compare the "exhaustive method", "enumeration method", and "Recursive Backtracking Method"

• If the relationship between information is hard to be found in the problem and cannot be broken down into independent sub-problems, it seems that after all possible situations are taken into account and all solutions are listed, to determine and obtain the optimal solution.

• The implementation of the enumeration algorithm relies on loops and various possible situations in the issue of cyclic nested enumeration.

• Fixed-weight nested loops cannot be used for enumeration if the scale is not fixed. Some problems may be solved by converting enumeration objects to nested loops, but the more problems with any specified scale are the possibility of "enumeration" or "traversing" by recursive return methods.

3) backtracking and branch Restriction Policies

• The Backtracking Method searches for the solution tree in depth-first mode, while the branch restriction rule searches for the solution tree in width-first or minimum-consumption-first mode.

• In general, the solution objective of the backtracking method is to find all solutions that meet the constraints in the solution space tree, the goal of the branch restriction method is to find a solution that meets the constraints, or to find a solution that maximizes or minimizes the value of a target function in the solution that meets the constraints, that is, the optimal solution in a certain sense.

4) depth first and breadth first

• Depth first: Generally, not all nodes are retained by the depth first search method. The extended nodes are deleted from the data storage structure stack, generally, the number of knots stored in the data stack is the depth of the solution space tree, so it occupies less space. Therefore, when there are many nodes in the search tree and other methods are prone to memory overflow, deep-priority search is an effective solution.

• Breadth first: Generally, all nodes need to be stored, and the storage space occupied is much larger than the depth first search. Therefore, the problem of overflow and memory saving must be considered in programming. However, the breadth-first search method generally does not have backtracing operations, that is, the inbound and outbound operations, so the operation speed is faster than the depth-first search.

5) Dynamic Planning and search algorithms

• Search algorithms: In algorithms that solve optimization problems, search can be said to be "omnipotent. Therefore, dynamic planning can solve the problem, and search can certainly solve it. Dynamic Planning requires that the decision-making at the stage has no backward direction, but the search algorithm does not have this limit.

• The advantage of the Dynamic Planning Algorithm in terms of time efficiency is that the search is incomparable, but the dynamic planning always traverses all states, and the search can exclude some invalid states. It is possible to cut out a large number of unnecessary states, so the space overhead is often much lower than dynamic planning.

• Dynamic Planning is a bottom-up recursive solution, and the top-down solution is used for both deep-first search and breadth-first search.


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.