Search algorithm basic tutorial

xiaoxiao2021-03-06  20

The search algorithm is a method of exhaustion of a problem with a high performance of the computer, resulting in a method of solving the problem. The search process actually constructs a solution tree based on the initial condition and extension rules and finds a node that meets the target state. All search algorithms are implemented from its final algorithm, can be divided into two parts - control structure and generating systems, and all algorithms are optimized and improved by modifying their control structures. It is now mainly discussed, so the system is made as follows: function expendnode (Situation: Tsituation; ExpendwayNo: Integer): Tsituation; indicates that the node status SITUTION is expanded with the EXPENDWAYNO expansion rule, and Returns the state after the extension. (The algorithm description language used herein is PASCAL.) 1. The backtracking algorithm is the most basic algorithm in all search algorithms. It uses a "walking" ideas as its control structure, which is quite A method of constructing a hot-traversed approach is used to find or all solutions and optimal solutions. The specific algorithm is described as follows: [Non-intended algorithm] node (Node type) = Record Situtation: Tsituation; Way-no: integer (number of extended rules); End List: array [1..max (maximum depth)] of node; POS (current extension node number): integer; list <-0; pOS <-1; list [1] .situation < - Initial state;

while (POS> 0 (with road can be taken)) AND ([not reached the target]) DOBEGIN if Pos> = max life (data overflow, jump out the main program); list [POS] .ver -NO: = List [POS] .way-no 1; if (list [POS] .ver-no <= totalexpendmethod) (if there is any extension rule) Begin if (you can use the current extension rule) THEN BEGIN (use of the Way Rule Rules Extended Current Node) List [POS 1]. Situation: = Expendnode (List [POS]. Situation, List [POS] .way-no); list [POS 1] .ver- NO: = 0; POS: = POS 1; end-if; end-if else begin Pos: = POS-1; end-elsend-while; [Recursive Algorithm] Procedure Backtrack (Situation: Tsituation; Deepth: integer); Var i: integer; begin if deepth> max life (space to get the limit, jump out of this process); if situation = target dam (find the target); for i: = 1 to TotaleXpendMethod do Begin Backtrack (Expendnode (Situation, I), Deepth 1); end-for; end; example: one M * m There is a horse on a note on the board, requiring a route from this point from which you don't repeat the board.

Evaluation: The retractable algorithm has less consumption of space. When it is used with the branching boundary method, there is a good effect on the problem of the level of the solution in the solution tree. However, it should be avoided in the same problem with the relay node to avoid cycling. Second, depth search and the intensive control structure and generating system of breadth search and generating systems are very similar, and the unique difference is to select the extension node. Since it retains all the relay nodes, a part of the repeated nodes can be removed when the subsequent node is generated, thereby improving search efficiency. Both algorithms extend all child nodes of a node each time, and differences, depth search next extension is one of this extended child node, and the breadth sexy expansion is this extended node Brother node.

In the specific implementation, in order to improve efficiency, different data structures are used. [Search] node (Node type) = Record Situtation: Tsituation; Level: Integer; Last: Integer (Parent Node): End list: Array [1..max (maximum number of nodes)] of node; Open (total number of nodes): Integer; Close (to extension Node number) : Integer; New-S: Tsituation; (New Node) list <-0; open <-1; close <-0; list [1] .situation <- initial status; list [1] .level: = 1; List [1] .last: = 0;

while (Close open: array [1..max] of node; (to be extended) Close: array [1. .Max] of node; (expanded node table) OpenL, Closel: Integer; (Length of Table) New-S: Tsituation; (New State) Open <-0; close <-0; OpenL <-1; closel <-0; open [1] .situation <- initial state; open [1] .level <-1; open [1] .last <-0;
while (openl> 0) AND (Closel

Open [OpenL]. Situation: = new-S; Open [OpenL] .level: = Close [Closel] .level 1; Open [OpenL] .last: = closel; end-if end-for; END; example: Maze problems, solve the shortest path and the accessible path. Evaluation: Bright Search is a better way to solve the optimal solution, which will be further optimized later. Depth search is mostly required to only be demanded, and the repetitive nodes in the solution tree are used more and repeatedly, it is often used, but it is often replaced by a branching or retrieval algorithm. http://www.mydrs.org big banyan tree

转载请注明原文地址:https://www.9cbs.com/read-45509.html

New Post(0)