Artificial intelligence --- search algorithm

(1) Dijkstra-Prim algorithm and Kruskal algorithm

        The basic idea of ​​the Dijkstra-Prim algorithm: All nodes are divided into two groups, one is the selected selected_node (list type), and the other is candidate_node. First, take any node and add it to selected_node, then traverse the head node in selected_node, and the tail node in candidate_node , select the edge with the smallest weight among the edges that meet this condition, and add it to the minimum spanning tree. The tail node of the selected edge is added to selected_node, and deleted from candidate_node. Until there is no candidate node in candidate_node (this loop condition requires that all nodes have edge connections, that is, the number of edges must be greater than or equal to the number of nodes -1, this condition must be added before the loop starts, otherwise there may be nodes that are always in the candidate, resulting in infinite loop).
        The basic idea of ​​the Kruskal algorithm: first sort the edges from small to large in weight, and select the edge with the smallest weight first. If the two nodes of the edge are different components, add it to the minimum spanning tree, otherwise calculate the next edge, until All edges are traversed.

Use the Dijkstra-Prim algorithm and the Kruskal algorithm        respectively to find a minimum length tree in the figure below
spanning tree.

 Dijkstra-Prim algorithm:

 Kruskal's algorithm:

 mark answer:

(2) Graph search algorithm

         Consider the following state diagram, the numbers on the edges are the path costs. Under the same node expansion condition, the selection node expansion follows the alphabetical order ( eg S->X->A should be expanded before S->X->B , S->A->Z should be expanded after S->B-> A was expanded before) .
1 ) Please use the cost-based unified search algorithm, what is the order in which the states are expanded? What is the return path?
2 ) Consider doing an A* graph search on the graph above . Action costs and heuristic values ​​are plotted in the figure. Please give what is the order in which the states are expanded? What is the return path?

answer:

1) Apply cost-based unified search, the order in which state nodes are expanded is: start, B, A, D, C, Goal. The returned path is: Start-AD-Goal.

2) Using the A* graph search algorithm, the order in which states are expanded is: Start, B, A, D, C, Goal. The returned path is: Start-AD-Goal.

The expansion sequence is as shown in the figure:

Guess you like

Origin blog.csdn.net/qq_63976098/article/details/131370997