Data structure-6.3 figure

Preface-Data Structure

The data structure needs to be chewed repeatedly, and the answers to the problems encountered in the development can be obtained at any time.

Graph traversal

  • definition
  • Starting from a vertex in the graph to visit the rest of the vertices in the graph, and each vertex is visited only once, it is called the traversal of the
    graph. The traversal algorithm of the graph is the basis for solving the connectivity problem of the graph, topological sorting, and finding critical paths.

Depth first (stack)

  • main idea
  • First take any vertex and then go down, the ones that have been visited are recorded as 1 and those that are not are recorded as 0
  • Then go to the next node for convenience. If all the vertices below it have been accessed, return to the previous vertex and continue to traverse
  • Until all vertices are visited
  • For example, for the undirected graph G7. There can be multiple depth-first search traversal sequences starting from each vertex. In the undirected graph G7, the depth-first search traversal sequence starting from vertex 0 is as follows, Ps: Vertex can be Access in any order so there are many orders
    Insert picture description here
  • answer
0326154
0326145

Breadth first (queue)

  • main idea
  • Use the queue to take any vertex to start traversal and then visit subsequent nodes
  • If the vertices connected to the node are out of the queue after traversing
  • Until everything is traversed
  • For example, for the undirected graph G7 shown in the figure below, there can be many kinds of breadth-first search traversal sequences starting from vertex 1, and only three are given below, and the others can be similarly analyzed. In the undirected graph G7, the breadth-first search traversal sequence starting from item 1 is as follows:Insert picture description here
  • answer
12345678
13247648
12354768

Guess you like

Origin blog.csdn.net/weixin_41732253/article/details/109612325